首页 > 其他 > 详细

跟踪对象属性值的修改, 设置断点(Break on property change)

时间:2016-02-02 14:50:52      阅读:216      评论:0      收藏:0      [点我收藏+]
  • 代码
    •   
      //Break on property change
      (function () {
          var localValue;
      
          Object.defineProperty(targetObject, ‘propertyName‘, {
              get: function() { //any access to the target property will call this method
                  return localValue;
              },
              set: function(val) { //any modification to the target property will call this method
                  localValue = val;
                  debugger;
              }
          });
      }());

       

  • Object.defineProperty
    • reference
    • Object.defineProperty是ECS5属性,所以IE8以下无效
    • 实际应用例子
      • 数据双向绑定
        •   
          Object.defineProperty(demo,‘foobar‘,{
            get:function(){
              return v;
            },
            set:function(e){
              v = e;
              sow();
            }}
          );
          
          function sow(){
             $(‘body‘).html(demo.foobar) 
          }

           

      • 手动设置断点
      • 设置属性不可变
      • 移除属性
        •   
          get: function () {
                throw new Error(‘Most middleware (like ‘ + name + ‘) is no longer bundled with Express and must be installed separately. Please see https://github.com/senchalabs/connect#middleware.‘);
              }

           

  • debugger

跟踪对象属性值的修改, 设置断点(Break on property change)

原文:http://www.cnblogs.com/gentlemint/p/5177089.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!