1 Function.prototype.method =
function(name, func) {
2 if (!
this.prototype[name]) {
3 this.prototype[name] =
func;
4 }
5 };
6
7 //根据数字的正负来判断使用哪个方法
8 Number.method('integer',
function() {
9 return Math[
this < 0 ? 'ceil' : 'floor'](
this);
10 });
11 document.writeln((-10 / 3
).integer());
12
13 //移除字符串末端空白的方法
14 String.method('trim',
function() {
15 return this.replace(/^\s+|\s+$/g, ''
);
16 });
17 document.writeln('"' + " neat ".trim() + '"');
DC大牛的写法感觉和YUI很相似
转载于:https://www.cnblogs.com/qzsonline/archive/2012/07/09/2582541.html