繁体   English   中英

我可以限制Javascript的Array.prototype扩展的范围吗?

[英]Can I limit the scope of Javascript's Array.prototype extensions?

我想限制扩展数组的范围

Array.prototype.myExtension = function() { 
// do something;
// return something;
};

到当前的JS模块。 此扩展名在其他模块中应该是不可见的。

解决方法是在另一个作用域(iframe或Web worker)中沙箱化Array或一般地定义该方法并与一个array对象一起调用 (或应用 )。

modulenamespace.myExtension = function() { 
// do something;
// return something;
}


modulenamespace.myExtension.call(array)

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM