我试图不明显地重复问题,因为我已经看到了一些关于 Douglas Crockford 的 Javascript the Good parts book 的问题/答案
我理解大部分代码
Function.prototype.method = function (name, func) {
this.prototype[name] = func;
return this;
};
Function.method('inherits', function (Parent) {
this.prototype = new Parent( );
return this;
});
var Mammal = function (name) {
this.name = name;
}.method('get_name', function () {
return this.name;
}).method('says', function() {
return this.saying || '';
});
var Cat = function (name) {
this.name = name;
this.saying = 'meow';
}.inherits(Mammal)
var myCat = new Cat('bagsley');
myCat.get_name();
我遇到的问题是 this.prototype[name] 为什么不写成 this.prototype.name;我知道返回它允许链接,这里的语法看起来与 jQuery 非常相似,但我仍然没有得到原型 [名称] 部分
感谢任何帮助