Skip to content

Instantly share code, notes, and snippets.

@lili21
Last active December 29, 2015 07:28
Show Gist options
  • Save lili21/7635784 to your computer and use it in GitHub Desktop.
Save lili21/7635784 to your computer and use it in GitHub Desktop.
javascript good parts function
//原型继承
if (typeof Object.beget !== 'function') {
Object.create = function(o) {
var F = function() {};
F.prototype = o;
return new F();
};
}
//var new_o = Object.create(old_o);
//扩充功能
Function.prototype.method = function(name, func) {
if (!this.prototype[name]) {
this.prototype[name] = func;
}
return this;
};
//取整
Number.method('integer', function() {
return Math[this < 0 ? 'ceil' : 'floor'](this);
});
//移除首尾空白
String.method('trim', function() {
return this.replace(/^\s+|\s+$/g, '');
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment