0
好吧,我正在创建一个JavaScript链接方法,我试图归档主要的obj或类有权访问4个属性,这些属性是函数和该属性必须能够访问主obj无法访问的一些函数。限制对主要obj对其属性的Javascript属性的访问
下面一个例子:
var Main = function(){
return {
property1:function(){
return this;
},
property2:function(){
return this;
},
etc:function(){
return this;
}...
}
}
要执行,你知道它是这样的:
Main().property1().property2().etc();
主要访问它的属性,但Main
不能访问这个特性是属性Main
的物业。以更简单的方式:just the properties of Main must have access, not Main
。
下面的例子:
Main().property().innerProperty1().innerProperty2().etc()//cool, property1 can access to innerProperty 1 and 2 and etc()
,但如果我想这样做:
Main().innerProperty() // ERROR, Main does not have acccess to innerProperty()
莫非在的javascrip可能吗?请记住,必须是可链接的。
我对你的例子感到困惑,因为你对每个“属性”所做的只是返回Main,所以它将有权访问Main可访问的所有属性。但是链接本身有什么意义呢? – Tony
因为如果主要访问将具有缺乏意义的内部属性。所以Main不能访问它1:由于缺乏意义和2,因为内部属性不会以任何方式影响Main – Ligth