ThinkChat2.0新版上线,更智能更精彩,支持会话、画图、阅读、搜索等,送10W Token,即刻开启你的AI之旅 广告
伪类 原型 // 先构造一个对象,然后构造一些类似的对象 var myMammal = { name : 'Herb the Mammal', get_name: function() { return this.name; }, says : function() { return this.saying || ''; } }; // 差异化继承 var myCat = Object.create(myMammal); myCat.name = 'Herb'; myCat.saying = 'meow'; myCat.purr = function(n) { var i, s = ''; for(i = 0; i < n; i++) { if(s) { s+='-'; } s += 'r'; } return s; }; myCat.get_name = function() { return this.says + ' ' +this.name + ' ' + this.says; }; var mammal = function(spec) { var that = {}; that.get_name = function() { return spec.name; }; that.says = function() { return spec.saying || ''; }; return that; }; var myMammal = mammal({name: 'Herb'});