How does naming an anonymous function in JavaScript make a difference?

后端 未结 4 610
北恋
北恋 2021-02-14 07:08

I am analyzing the following two urls from John Resig\'s site, but I am not understanding how giving a name to the anonymous function has made a difference.

My understan

4条回答
  •  夕颜
    夕颜 (楼主)
    2021-02-14 07:30

    In the first case, the yell method is trying to access ninja.yell, regardless of which object calls it. Whereas in the second, it tries to call yell which exists because the function is named.

    It is NOT a good example. A good example would use this.yell instead of ninja.yell, thus getting the yell method from the current object.

提交回复
热议问题