MyClassfunction () {varA1; // internal Member B2; // internal Member this. c3; // object member} MyClass. prototype. d4; // object member (via prototype extension) objnewMyClass (); alert (obj. A );//... syntaxHighlighter
MyClass = function (){
Var A = 1; // internal Member
B = 2; // internal Member
This. C = 3; // object Member
}
MyClass. prototype. D = 4; // object member (via prototype extension)
Obj = new MyClass ();
Alert (obj. A); // undefined
Alert (obj. B); // undefined
Alert (obj. C); // 3
Alert (obj. D); // 4
Alert (obj. hasOwnProperty ('C'); // true
Alert (obj. hasOwnProperty ('d); // false
/* A boring exercise */
MyClass = function (){
This. A = 1;
}
MyClass. prototype. X = function (){
This. B = 2;
}
MyClass. prototype. Y = function (){
This. Z = function (){
This. C = 3;
}
}
Obj = new MyClass ();
Alert (obj. A); // 1
Obj1 = new obj. X ();
Alert (obj1. B); // 2
Obj2 = new (new obj. Y (). Z ();
Alert (obj2.C); // 3
From the Delphi blog