javascript this的意思

this指向哪里?

一般而言,在Javascript中,this指向函数执行时的当前对象。

In JavaScript, as in most object-oriented programming languages, this is a special keyword that is used within methods to refer to the object on which a method is being invoked.

——jQuery Fundamentals (Chapter 2), by Rebecca Murphey

值得注意,该关键字在Javascript中和执行环境,而非声明环境有关。

The this keyword is relative to the execution context, not the declaration context.

作为函数调用时,this 绑定到全局对象;作为方法调用时,this 绑定到该方法所属的对象。

可参考下面这个文章

http://www.cnblogs.com/justany/archive/2012/11/01/the_keyword_this_in_javascript.html

http://www.ibm.com/developerworks/cn/web/1207_wangqf_jsthis/

http://yehudakatz.com/2011/08/11/understanding-javascript-function-invocation-and-this/?cm_mc_uid=10332690919714457452748&cm_mc_sid_50200000=1445838114

原文地址:https://www.cnblogs.com/terryc/p/4910832.html