JavaScript function binding (this keyword) is lost after assignment

前端 未结 5 790
甜味超标
甜味超标 2020-11-30 12:28

this is one of most mystery feature in JavaScript, after assigning the object method to other variable, the binding (this keyword) is lost

var john = {
  nam         


        
5条回答
  •  情深已故
    2020-11-30 13:21

    As I understand it, you're only assigning that method to the variable "fx." The context of the john object doesn't come along with it.

    Off the top of my head, "this" in the context of fx will refer to the global object, which in the context of a browser is (I believe) equivalent to your window object.

    (editing to clarify global object. Sort of)

提交回复
热议问题