js 给 对象添加扩展方法

像c# 那样 点出来 ,而不是 函数 括号包着 , 比如 想给所有 Object 添加一个 isSuccess 方法 ,可以 这样写

// js 给 object 添加 扩展方法
Object.defineProperty(Object.prototype, "isSuccess", {
    value: function isSuccess() {
        return this.resultCode === "1";

    },
    writable: true,
    configurable: true
})

  

posted @ 2022-01-21 11:00  ifnk  阅读(136)  评论(0编辑  收藏  举报