zoukankan      html  css  js  c++  java
  • underScore学习1:匿名函数中call(this)的作用

    匿名函数中(function(){}).call(this) 中的.call(this) 有什么用?

    • 我们都知道,.call()可以改变函数执行时的context,即this的指向,源码中的.call(this)
    • 主要就是,把当前的context传递给匿名函数。
    • So, if for whatever reason you use this, it's a way to make the IIFE act as if it were a member function of Foo,
    • specifically when creating instances of a user-defined object type.
        function Foo(){
        (function(){
            console.log(this);  //Foo
        }).call(this);
    
        (function(){
            console.log(this); //undefined in strict or global
        })();
    }
    
    var bar = new Foo;
    
  • 相关阅读:
    产品经理经常犯的错误李可按
    skills_hive
    skills_office
    skills_idea
    skills_linux
    skills_ubuntu
    skills_git
    skills_redis
    skills_centos
    problems_hive
  • 原文地址:https://www.cnblogs.com/goodearth/p/6234694.html
Copyright © 2011-2022 走看看