Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
我正在创建一个名为“Burn”的新项目。这将类似于可汗学院的计算机科学项目。我怎么会有一个“私有”的 JavaScript 上下文,它不能使用除指定方法之外的任何方法?
您可以使用IIFE(immediatelyinvoked function expression) 并在其中编写代码。您可以window在该上下文中重新定义对象,因此您无法访问窗口对象上的其他方法。
IIFE
window
(function (window){ //code and other functions here // here window is undefined })();
但我不确定你为什么想要那个。
见jsFiddle