标签:
function Foo(){ }; console.log(Foo.prototype); //Object{} console.log(Foo.prototype .constructor); // function Foo(){}
function Foo(){}; console.log(Foo.prototype); //Object{} var f=new Foo(); console.log(f.__proto__); // Object{} console.log(Foo.prototype==f.__proto__) ; // true
function animal(name){ this.name=name; } animal.prototype.color="white"; var cat1=new animal("cat"); var cat2=new animal(‘dog‘); cat1.color; //white cat2.color; //white
function Foo(){}; console.log(Foo.__proto__); //function(){} console.log(Function.prototype); //function(){} console.log(Foo.__proto__==Function.prototype); //true
console.log(Function instanceof Function); //true onsole.log(Function.prototype.__proto__); // Object{}
function Foo(){}; var f=new Foo(); Foo.prototype.age=12; f.name="dog"; console.log(f.age); console.log(f.hasOwnProperty(‘name‘)); //true console.log(f.hasOwnProperty(‘age‘)); //false
function Foo(){}; Foo.prototype.age=12; var f=new Foo(); console.log(Foo.prototype.isPrototypeOf(f)); //true
function Foo(){}; Foo.prototype.age=12; var f=new Foo(); f.name="dog"; console.log(Object.getPrototypeOf(f)); // Object{age:12}
var a={age:12}; var b=Object.setPrototypeOf({},a); console.log(b.age); //12
标签:
原文地址:http://www.cnblogs.com/chtt/p/5793707.html