Visualizzazione dei risultati da 1 a 5 su 5
  1. #1

    Prototype risalire a valore in obj parent

    Ciao.
    Codice PHP:
    /* A "constructor" function for creating objects of a -
       MyObject1 - type.
    */
    function MyObject1(formalParameter){
        
    /* Give the constructed object a property called - testNumber - and
           assign it the value passed to the constructor as its first
           argument:-
        */
        
    this.testNumber formalParameter;
    }

    /* A "constructor" function for creating objects of a -
       MyObject2 - type:-
    */
    function MyObject2(formalParameter){
       
    /* Give the constructed object a property called - testString -
          and assign it the value passed to the constructor as its first
          argument:-
        */
        
    this.testString formalParameter;
    }

    /* The next operation replaces the default prototype associated with
       all MyObject2 instances with an instance of MyObject1, passing the
       argument - 8 - to the MyObject1 constructor so that its -
       testNumber - property will be set to that value:-
    */
    MyObject2.prototype = new MyObject1);

    /* Finally, create an instance of - MyObject2 - and assign a reference
       to that object to the variable - objectRef - passing a string as the
       first argument for the constructor:-
    */

    var objectRef = new MyObject2"String_Value" );
    //alert(objectRef.testNumber);
    //alert(objectRef.testString);
    //var val = objectRef.toString;
    objectRef.testNumber=10;
    alert(objectRef.testNumber); 
    Se a questo punto volessi recuperare
    il valore 8 che ho da fà


    Without faith, nothing is possible. With it, nothing is impossible
    http://ilwebdifabio.it

  2. #2
    Esamina il prototype:
    codice:
    alert(objectRef.constructor.prototype.testNumber);

  3. #3
    Originariamente inviato da Mega69
    Esamina il prototype:
    codice:
    alert(objectRef.constructor.prototype.testNumber);
    Abbi pazienza ma facendo cosi mi appare un undefined
    mi perdo qc

    Without faith, nothing is possible. With it, nothing is impossible
    http://ilwebdifabio.it

  4. #4
    Devi aggiungere questo dopo MyObject2.prototype = new MyObject1( 8 );
    codice:
    MyObject2.prototype.constructor = MyObject2;
    Senza di questo il costruttore resterebbe MyObject1.

  5. #5
    Originariamente inviato da Mega69
    Devi aggiungere questo dopo MyObject2.prototype = new MyObject1( 8 );
    codice:
    MyObject2.prototype.constructor = MyObject2;
    Senza di questo il costruttore resterebbe MyObject1.

    Without faith, nothing is possible. With it, nothing is impossible
    http://ilwebdifabio.it

Permessi di invio

  • Non puoi inserire discussioni
  • Non puoi inserire repliche
  • Non puoi inserire allegati
  • Non puoi modificare i tuoi messaggi
  •  
Powered by vBulletin® Version 4.2.1
Copyright © 2025 vBulletin Solutions, Inc. All rights reserved.