Javascript OOP augmenting with prototype

来源:互联网 发布:烟台java培训班哪个好 编辑:程序博客网 时间:2024/05/29 16:44

prototype reference

Allows the addition of properties to all objects of type Object.


we can extend the functionality of build-in types:

// Add a method conditionally.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);});document.writeln((-10 / 3).integer(  ));  // −3


原创粉丝点击