首页 > 编程语言 > 详细

[Javascript] Private Variables with IIFEs

时间:2019-12-08 00:59:11      阅读:123      评论:0      收藏:0      [点我收藏+]

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

 

[Javascript] Private Variables with IIFEs

原文:https://www.cnblogs.com/Answer1215/p/12003833.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!