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

Popular posts from this blog

html - How to style widget with post count different than without post count -

How to remove text and logo OR add Overflow on Android ActionBar using AppCompat on API 8? -

javascript - storing input from prompt in array and displaying the array -