I'm trying not to duplicate questions obviously as I have seen some questions/answers regarding Douglas Crockford's Javascript the Good parts book
I understand most of this code
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();
what I'm having trouble getting is the this.prototype[name] why isn't it written as this.prototype.name; I know returning this allows chaining and the syntax here looks very similar to jQuery but I still don't get the prototype[name] part
Any help is apprecaited thanks