function Gadget(name,color){ this.name=name; this.color=color; this.whatAreYou=function(){ return 'I am a ' + this.color + ' ' + this.name; };}Gadget.prototype={ price:100, rating:3, getInfo:function(){ return 'Rating: ' + this.rating + ', price: ' + this.price; }};var newtoy=new Gadget('webcam','black');new.rating;//3newtoy.constructor === Gadget;//true上述例子摘自《面向对象编程指南》一书
添加回答
举报
0/150
提交
取消