The sandbox in JavaScript refers to a completely independent area that uses its own independent properties and methods. The basic format of the sandbox in js is "(function(){})(...) "; Sandbox mode is generally used when writing third-party frameworks or writing plug-ins for third-party frameworks or writing components with independent functions.
The operating environment of this article: windows7 system, javascript version 1.8.5, DELL G3 computer
What does javascript sandbox mean?
The concept of sandbox in js
Sandbox
The sandbox is a completely independent area in js that uses Independent properties and methods
Basic format of sandbox in js
(function(){})()
Self-calling function (immediate execution of function)
Sandbox usage specifications
Write all variable definitions at the top
Place logic code in the middle
Finally, if necessary, expose some members to the outside world (such as jQuery, such as window. For example, window .=window.jQuery=$)
The purpose of sandbox
Sandbox mode is generally used when writing third-party frameworks
or for third parties Framework writing plug-in
or writing some components with independent functions
Advantages of sandbox mode
1. Sandbox mode uses IIFE, not Any global variables will be exposed to the outside world, which will not cause global variable pollution
2. All data in the sandbox is completely isolated from the outside world and cannot be modified by the outside world, which ensures To ensure the security of the code
Recommended study: "javascript basic tutorial"
The above is the detailed content of What does javascript sandbox mean?. For more information, please follow other related articles on the PHP Chinese website!