J
Jens Müller
In JS:TGP, Crockford defines a method called method:
"Throughout the book, a method method is used to define new methods.
This is its definition:
Function.prototype.method = function (name, func) {
this.prototype[name] = func;
return this;
};
It will be explained in Chapter 4."
So far, so good.
Then, in Chapter 4 in the section "Augmenting Types" he goes on:
"For example, by augmenting Function.prototype, we can make a method
available to all functions:
Function.prototype.method = function (name, func) {
this.prototype[name] = func;
return this;
};
By augmenting Function.prototype with a method method, we no longer have
to type the name of the prototype property. That bit of ugliness can now
be hidden."
Then in the section "Module" he uses it to augment String.
String.method('deentityfy', function () { ... return function () {
....}; }; ());
and then uses it as follows:
document.writeln('<">',deentityfy());
To what exactly is deentityfy added (and why is method available there),
and how exactly does it happen that deentityfy on a String literal gets
called?
- Jens
"Throughout the book, a method method is used to define new methods.
This is its definition:
Function.prototype.method = function (name, func) {
this.prototype[name] = func;
return this;
};
It will be explained in Chapter 4."
So far, so good.
Then, in Chapter 4 in the section "Augmenting Types" he goes on:
"For example, by augmenting Function.prototype, we can make a method
available to all functions:
Function.prototype.method = function (name, func) {
this.prototype[name] = func;
return this;
};
By augmenting Function.prototype with a method method, we no longer have
to type the name of the prototype property. That bit of ugliness can now
be hidden."
Then in the section "Module" he uses it to augment String.
String.method('deentityfy', function () { ... return function () {
....}; }; ());
and then uses it as follows:
document.writeln('<">',deentityfy());
To what exactly is deentityfy added (and why is method available there),
and how exactly does it happen that deentityfy on a String literal gets
called?
- Jens