首页 > 编程语言 > 详细

To add private variable to this Javascript literal object

时间:2015-03-16 15:50:26      阅读:271      评论:0      收藏:0      [点我收藏+]

 

You can use number as function/variable name, the numberic name can‘t be accessed from parent scope, but can be accessed by ‘this‘ in private scope.

 

var o=
    {
      attr1:‘value of attr1‘,
       1:‘private attr ,the index is 1‘,
       301:function(){
         console.log(‘private function , name is 2‘);
       },
       fun1:function(){
        console.log(this[1]);
         this[301].call(this);
      }
    };

o.fun1();

 

To add private variable to this Javascript literal object

原文:http://www.cnblogs.com/zyip/p/4341717.html

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