道格拉斯·克罗克福德在他的书(第4页)中写道:
在整本书中,一个method方法用于定义新方法,这是它的定义:
Function.prototype.method = function (name, func) {
this.prototype[name] = func;
return this;
};
Run Code Online (Sandbox Code Playgroud)
然后他开始使用它method来添加方法Number, String, Function, Object, Array, RegExp,这里是完整的列表:
P33:
Number.method('integer', function () {...});
String.method('trim', function () {...});
Run Code Online (Sandbox Code Playgroud)
P40(不确定第41页是否存在印刷错误:结束()):
String.method('deentityify', function () {...}());
Run Code Online (Sandbox Code Playgroud)
P43和P44:
Function.method('curry', function () {...});
Run Code Online (Sandbox Code Playgroud)
P47(我在这里很困惑,不知道为什么Crockford定义new方法,而且他似乎从不new在书中使用方法):
Function.method('new', function () {...});
Run Code Online (Sandbox Code Playgroud)
P48:
Function.method('inherits', function (Parent) {...});
Run Code Online (Sandbox Code Playgroud)
P54:
Object.method('superior', function (name) {...});
Run Code Online (Sandbox Code Playgroud)
P62:
Array.method('reduce', function (f, value) {...});
Run Code Online (Sandbox Code Playgroud)
P79:
Array.method('pop', function () {...});
Array.method('push', function () {...});
Array.method('shift', …Run Code Online (Sandbox Code Playgroud)