2. Type = Id = Category = Group var a = {type:1};
int memory▼ recognize▼ scalable● var b = {type:2};
var a = {type:"food"};
String memory▲ recognize▲ scalable▼
var b = {type:"tool"};
Object memory▼ recognize▲ scalable▲ var food = {};
var tool = {};
Self(Recusive) - Reference var a = {type:food};
var food = {}; var b = {type:tool};
var tool = {};
alert( food.type );
Conclusion = Function
var food = function(){};
var tool = function(){};
var a = {type:food};
var b = {type:tool};
alert( a.type ); // food
alert( food.type ); // undefined
3. function test(){ Function['test'] = {
... ...
} prototype:{
alert( typeof test.prototype );
constructor:Function['test']
alert( test === test.prototype.constructor ); }
};
var a = new test( 3 ); var a = {
__proto__:test.prototype
alert( a.constructor === test ); };
alert( a instanceof test );
a = test.call( a, 3 ) || a;
function test( $val ){ a={
this.val = $val; __proto__:test.prototype,
}
val:3
};
function test( $val ){ a = {};
this.val = $val;
return {};
}
4. function test1(){ var a = new test1;
}
function test2(){ alert( a.constructor === test1 );
} alert( a instanceof test1 );
test1.prototype.constructor = test2;
alert( test2 === test1.prototype.constructor );
test1.prototype = test2.prototype; function test(){
alert( test2 === test1.prototype.constructor ); }
test.prototype.val = 3;
function test(){
} var a = new test, b = new test;
test.prototype.action = function(){};
alert( a.val );
var a = new test, b = new test;
a.val = 5;
alert( a.action === b.action ); alert( b.val );
5. function parent(){ a={
} __proto__:child.prototype
parent.prototype.add = function(){}; };
function child(){ //1. a[???]
} //2. a.__proto__[???]
child.prototype.action = function(){};
a.add === undefined
var a = new child;
a.add();
Goal = a.__proto__.__proto__.add();
1. a.__proto__ = child.prototype;
2. a.__proto__.__proto__ = child.prototype.__proto__ = parent.prototype;
3. child.prototype = new parent;
4. a.__proto__.__proto__.add = parent.prototype.add;
6. function parent(){
}
parent.prototype.add = function(){};
parent.prototype.remove = function(){};
...
function child( a, b ){
this.a = a;
this.b = b;
}
child.prototype = new parent;
child.prototype.action1 = function(){};
child.prototype.action2 = function(){};
...
var a = new child;
a.a; // a.a
a.b; // a.b
a.action1(); // a.__proto__.action1
a.action2(); // a.__proto__.action2
a.add(); // a.__proto__.__proto__.add
a.remove(); // a.__proto__.__proto__.remove
7. function test( a, b ){ function test( a, b ){
if( this == window ){ ...
return new test( a, b ); }
}else{
this.a = a; test.prototype.action1 = function(){};
this.b = b; test.prototype.action2 = function(){};
}
} test.prototype = {
constructor: test.prototype.constructor,
var a = test( 3, 5 ); action1: function(){},
var b = new test( 3, 5 ); action2: function(){}
};
alert( a.constructor === b.constructor );
function parent( a ){
this.a = a;
}
function child( a, b ){
this.super( a );
this.b = b;
}
child.prototype = new parent;
child.prototype.super = parent;
var a = new child( 3, 6 );
alert( a.a );