码迷,mamicode.com
首页 > 编程语言 > 详细

To add private variable to this Javascript literal object

时间:2015-03-16 15:53:44      阅读:143      评论: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
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!