jquery - Access parent function properties Javascript -
i have javascript class
function palette() { this.selecteditem = ""; this.addbox = function() { // different approach, create fake box b = $("<div id='box-palette' class='box'>box</div>"); b.insertbefore('#cont'); b.mousedown(function() { this.selecteditem = "box"; // here want access palette#selecteditem console.log(palette); }); } }
how can access property of class in function want pass jquery?
any appreciated. thanks!
since tagged jquery use $.proxy() pass parent context callback method
function palette() { this.selecteditem = ""; this.addbox = function () { // different approach, create fake box b = $("<div id='box-palette' class='box'>box</div>"); b.insertbefore('#cont'); b.mousedown($.proxy(function () { this.selecteditem = "box"; // here want access palette#selecteditem console.log(palette); }, this)); } }
note: bind() not used because of lack ie<9 support
Comments
Post a Comment