JavaScript学习手册(50)
发布日期:2021-05-09 19:29:16 浏览次数:20 分类:精选文章

本文共 2278 字,大约阅读时间需要 7 分钟。

IIFE������ Immediately Invoked Function Expression������������������������������������������������JavaScript���������������������������������������������������������������������������������������������������������������������������������������������������������������IIFE������������������������������������������JavaScript���������������������

IIFE���������

  • ���������������IIFE���������������������������������������������������������������������������������������������������������������������������������
  • ������������������������������������IIFE������������������������������������������window������������������������������������������������
  • ���������������������������������������������������������������������������������

������������������

���������������������

var a = 4
console.log(a)(function() {
var a = 1
function test() { console.log(++a) }
function test2() { console.log('test2()') }
window.$ = function() {
return { test: test }
}
})
$().test() // ������: 1, ���������������test������
  • IIFE������(...)������������������������������������������������������������
  • ���������������var a = 1������������������a = 4���������������
  • ���������������������������test������������������������������������������������������window.$ = ...������������������������������������������������������������
  • $().test()������������IIFE���������window.$���������������������������������������������

������this���������

this���������������������������������������������������������������this���������������������������������������

  • ������������test(): this������������������������������window������
  • p.test(): this������p���������
  • new test(): this������������������test���������
  • p.call(obj): this���������������������obj���
  • ���������������������������������������������������������������������������������������this���������������������������������������������������������������������

    ������������

    ���������������������������������������������������������������������������������IIFE������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������

    上一篇:JavaScript学习手册(51)
    下一篇:软考中级-系统集成项目管理工程师-考试学习计划

    发表评论

    最新留言

    很好
    [***.229.124.182]2025年04月22日 08时39分37秒