JavaScript this refers to window instead of object inside function

倾然丶 夕夏残阳落幕 提交于 2019-11-27 23:12:05

this has nothing to do with scope. It is determined by context.

greeting() calls the function with no context, so this is the default object (window in a browser).

The this, references is not related to scope, it depends on the calling context.

As per the MDN doc,

In general, the object bound to this in the current scope is determined by how the current function was called

Try person.nickname, this refers to the var greeting in your case

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!