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很相似

相关文章:

  • 2021-08-23
  • 2021-11-30
  • 2022-03-08
  • 2021-08-03
  • 2021-12-10
  • 2021-11-25
  • 2022-03-02
猜你喜欢
  • 2022-12-23
  • 2021-11-26
  • 2022-01-06
  • 2022-12-23
  • 2022-12-23
  • 2021-12-15
  • 2022-01-08
相关资源
相似解决方案