Giter VIP home page Giter VIP logo

Comments (7)

YuYuBei avatar YuYuBei commented on May 18, 2024 5

因为上面第三行的时候,把foo函数重写了,所以未来只会有 “嘻嘻,我出现了哦”

from til.

YuYuBei avatar YuYuBei commented on May 18, 2024 2

试了下,这样就不行。

var foo = function() {
  console.log('你会发现我只出现一次哦,不管你调用几次')
  var foo = function() {
    console.log('嘻嘻,我出现了哦')
  }
  foo()
}
foo()
foo()

😢

这是因为你在第三行的时候,重新var了一下foo(新foo),这个新foo的作用域是在范围比较大的foo(旧foo)里面,所以不能把旧foo进行重新赋值为一个新foo,这样每次运行的时候,都是存在两个不同的foo

from til.

xiaohesong avatar xiaohesong commented on May 18, 2024 2

@YuYuBei 👍
@medeen 可以看下这个文章js的执行上下文 对js的执行有个了解

from til.

medeen avatar medeen commented on May 18, 2024

试了下,这样就不行。

var foo = function() {
  console.log('你会发现我只出现一次哦,不管你调用几次')
  var foo = function() {
    console.log('嘻嘻,我出现了哦')
  }
  foo()
}
foo()
foo()

😢

from til.

YuYuBei avatar YuYuBei commented on May 18, 2024

@xiaohesong 三克油,这些都是你自己翻译的吗?

from til.

xiaohesong avatar xiaohesong commented on May 18, 2024

@YuYuBei 嗯,看到一些不错的会记录下来

from til.

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.