• 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;
            }
        });
    }
  • 相关阅读:
    APICloud框架——获取本地图片信息
    APICloud框架--sublime使用自定义loader
    Felx布局(三)
    Flex布局(二)
    Linux时间与Windows差8个时区的问题解决方法
    警惕javascript代码中的“</script>”!
    字母数字推理题
    “黑客”究竟是什么
    博客园自定义博客侧边栏公告的过滤漏洞
    一行命令实现Android自动关机
  • 原文地址:https://www.cnblogs.com/shidengyun/p/5437690.html
Copyright © 2020-2023  润新知