Javascript literal object, reference to itself

前端 未结 4 1206
灰色年华
灰色年华 2020-12-16 23:44

I have this example code:

var foo = {

    self: this,

    init: function(){

        self.doStuff();
    },

    doStuff: function(){
        alert(\'doing         


        
4条回答
  •  借酒劲吻你
    2020-12-17 00:20

    Because at the time you declare the object literal this is not a reference to the object, but to whatever the calling context is.

提交回复
热议问题