JavaScript在原型上定义属性

Object.defineProperties(Number.prototype, {
    obj: {
        get: function () { return { add: p => this + p } }
    },
    add: { value: function (p) { return this + p } }
});
console.log((1).obj.add(5),(1).add(10))

猜你喜欢

转载自blog.csdn.net/slwsss/article/details/97888338