zoukankan      html  css  js  c++  java
  • Object.watch

    /*
     * object.watch polyfill
     *
     * 2012-04-03
     *
     * By Eli Grey, http://eligrey.com
     * Public Domain.
     * NO WARRANTY EXPRESSED OR IMPLIED. USE AT YOUR OWN RISK.
     
    */

    // object.watch
    if (!Object.prototype.watch) {
        Object.defineProperty(Object.prototype, "watch", {
              enumerable: false
            , configurable: true
            , writable: false
            , value: function (prop, handler) {
                var
                  oldval = this[prop]
                , newval = oldval
                , getter = function () {
                    return newval;
                }
                , setter = function (val) {
                    oldval = newval;
                    return newval = handler.call(this, prop, oldval, val);
                }
                ;
                
                if (delete this[prop]) { // can't watch constants
                    Object.defineProperty(this, prop, {
                          get: getter
                        , set: setter
                        , enumerable: true
                        , configurable: true
                    });
                }
            }
        });
    }

    // object.unwatch
    if (!Object.prototype.unwatch) {
        Object.defineProperty(Object.prototype, "unwatch", {
              enumerable: false
            , configurable: true
            , writable: false
            , value: function (prop) {
                var val = this[prop];
                delete this[prop]; // remove accessors
                this[prop] = val;
            }
        });
    }
  • 相关阅读:
    vim命令大全
    docer中运行crontab
    基于预加载的热区域数据的简单设计
    解析Health端点数据获取异常数据
    微服务链路调用耗时示例图
    Spring Cloud health节点通过注册中心扫描状态的简单实现
    转载:Service Mesh:重塑微服务市场--敖小剑
    Springboot统一参数验证方式
    Spirng boot 启动的时候进行监控检查不通过停止服务与自定义健康监控节点
    准备 Python3 和 Python 虚拟环境
  • 原文地址:https://www.cnblogs.com/shidengyun/p/5437690.html
Copyright © 2011-2022 走看看