Coder Social home page Coder Social logo

你还没搞懂this? about blog HOT 7 OPEN

ljianshu avatar ljianshu commented on May 16, 2024 5
你还没搞懂this?

from blog.

Comments (7)

mrslimslim avatar mrslimslim commented on May 16, 2024 3

let btn2 = document.getElementById('btn2'); let obj = { name: 'kobe', age: 39, getName: () => { btn2.onclick = () => { console.log(this);//window }; } };
这就是vue的methods里面不能使用箭头函数的原因吧

from blog.

yinyihui avatar yinyihui commented on May 16, 2024

~function(){ //this->window }();
能解释下这个写法吗?

from blog.

suchenrain avatar suchenrain commented on May 16, 2024

~function(){ //this->window }();
能解释下这个写法吗?

立即执行函数表达式(IIFE)的一种写法而已,通过~/+/-等运算符将函数体转换成函数表达式,最后加上()就能立即执行了。

from blog.

yinyihui avatar yinyihui commented on May 16, 2024

~function(){ //this->window }();
能解释下这个写法吗?

立即执行函数表达式(IIFE)的一种写法而已,通过~/+/-等运算符将函数体转换成函数表达式,最后加上()就能立即执行了。

原来如此,受教了!

from blog.

Raywh avatar Raywh commented on May 16, 2024

let btn2 = document.getElementById('btn2'); let obj = { name: 'kobe', age: 39, getName: () => { btn2.onclick = () => { console.log(this);//window }; } };
这就是vue的methods里面不能使用箭头函数的原因吧

??? 不能吗 ?

from blog.

vanBlayt avatar vanBlayt commented on May 16, 2024

受教了

from blog.

HduSy avatar HduSy commented on May 16, 2024

~function(){ //this->window }();
能解释下这个写法吗?

立即执行函数表达式(IIFE)的一种写法而已,通过~/+/-等运算符将函数体转换成函数表达式,最后加上()就能立即执行了。

原来如此,受教了!

可以~

from blog.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.