jQuery: how to access parent function “this” from inside anonymous function?

前端 未结 5 946
余生分开走
余生分开走 2020-12-28 16:07
...
$.fn.annotateEdit = function(image, note) {
    if (note) {
        this.note = note;
    } else {
        var newNote = new Object();
        newNote.id = \"new         


        
5条回答
  •  清歌不尽
    2020-12-28 16:24

    There is no dedicated language mechanism for it. The common pattern is to store the this in local (closure) variable (often named self or that) of the outer function:

    var self = this;
    var innerFunction = function() {
        self.x = 1;
    };
    

提交回复
热议问题