[Javascript] Private Variables with IIFEs

An IIFE (immediately invoked function expression) is when a function is called immediately after it is defined. These functions are defined and called once and are not accessed by other functions, variables, or from the global namespace. This is because it uses the grouping operator to make these function declarations an expression. Because of this one time invocation and lack of accessibility, we can use their function scope to hide variables from being access from anywhere else.

 

(function findName() {
  return 'hello'
})()

findName() // error

 

上一篇:[Delphi] Delphi版本号对照


下一篇:报错:Uncaught ReferenceError: JSENCRYPT_VERSION is not defined