13
Situation
function x(){
    var f = null;   // PROPRIEDADE PRIVADA DE x
    this.a = null;  // AS INSTANCIAS DE x TERÃO ACESSO A PROPRIEDADE a
    x.b = null;     // ACESSIVEL COMO x.a
}
function y(){
    x.call(this);   // HERANCA DE x
    this.c = null;
    y.d = null;
}
function z(){
    this.c = null;
    z.d = null;
}
z.prototype = x;
var t = new y;
console.log(t); // Object { a: null, c: null}
console.log(t.__proto__); // Object { constructor : y(), __proto__:Object }
                // NÃO ME EXIBE b NEM d
var p = new z;
console.log(p); // Object { c: null}
console.log(p.__proto__); // fuction x()
                // NÃO ME EXIBE b, MAS EU TENHO ACESSO p.b
Understanding
- x.bin fact is accessing the super global- window[x][b]and setando with- value = null.
- p.bhas access to- b, because he searches for the object- p, not finding passes to the- __proto__that is- x.- console.log(typeof x) // function console.log(typeof x.b) // object
In Javascript, almost everything is an object. All primitive types - with the exception of null and Undefined - are treated as objects. They may receive properties (assigned properties of some types are not persistent), and have all the characteristics of objects. MDN
Doubts
- The above understanding is correct?
- Why tdoes not have access tot.b, as well aspdoes not have access top.d?
- Why pdoes not have access top.a, even though it may__proto__ = x?
- x.bis the same as a statistical property?
@mgibsonbr, if you can help, I’ve read many of your answers, always very good.
– Guilherme Lautert
@bfavaretto also :D
– Guilherme Lautert
you know that the
this, is not always thethisthat you are using, it varies according to the scope... it is like a pointer..., another detail, that you have to consider, is that one does not see the other until it exists.– Ivan Ferrer
Guilherme, you know that neither I nor Gibson were notified of your comments above, right? I saw it by chance. See http://meta.pt.stackoverflow.com/q/943
– bfavaretto