I am reading the book "Javascript: The good parts".
Now I am reading chapter about Augmenting Types:
Function.prototype.method = function (name, func) {
this.prototype[name] = func;
return this;
};
UPDATE:
Why following code does not work?
js> Function.prototype.method("test", function(){print("TEST")});
typein:2: TypeError: this.prototype is undefined
But following code works without problems:
js> Function.method("test", function(){print("TEST")});
function Function() {[native code]}
Why this code works?
js> var obj = {"status" : "ST"};
js> typeof obj;
"object"
js> obj.method = function(){print(this.status)};
(function () {print(this.status);})
js> obj.method();
ST
"obj" is object.
But I can call method "method" on it.
What is the difference between Function.prototype.method and obj.method?