Javascript Object Layout
var Foo = function() {}; var o = new Object(); var f = new Foo(); console.log('f instanceof Foo =', f instanceof Foo,', f instanceof Function =', f instanceof Function,', f instanceof Object =', f instanceof Object); console.log('Foo instanceof Function =', Foo instanceof Function,', Foo instanceof Object =', Foo instanceof Object); console.log('o instanceof Object =',o instanceof Object,', o instanceof Function =', o instanceof Function,', o instanceof Object =', o instanceof Object); console.log('Object instanceof Function =', Object instanceof Function,', Object instanceof Object =', Object instanceof Object); console.log('Function instanceof Function =', Function instanceof Function,', Function instanceof Object =', Function instanceof Object); /** f instanceof Foo = true , f instanceof Function = false , f instanceof Object = true Foo instanceof Function = true , Foo instanceof Object = true o instanceof Object = true , o instanceof Function = false , o instanceof Object = true Object instanceof Function = true , Object instanceof Object = true Function instanceof Function = true , Function instanceof Object = true */
在chrome中进行了测试;
var Foo = function (f){};
var o = {};
var f = new Foo();
f.constructor 指向 function (f){},这个在图上没有显示出来;
o.constructor 指向 function Object() { [native code] }
Foo.prototype是一个对象Foo{};该对象的constructor指回function (f){};
Foo.prototype.__proto__是一个对象:Object {};
Object.prototype指向同样一个对象Object{};这个对象的constructor指回function Object() { [native code] };
Foo.__proto__,Object.__proto__,Function.__proto__,Function.prototype都指向了function Empty() {},
这个function Empty() {}就是Function.prototype;这个名字起的好,而且这个还不像是对象;
function Empty() {}的__proto__指向Object{},而Object{}的__proto__指向了null;
天下万物生于有,有生于无--《道德经》