Monday, 15 June 2015

javascript - Access parent object from inside object -



javascript - Access parent object from inside object -

i wondering if there's elegant way of doing next code instead of having phone call parent object "that" first. if seek using "this" within ajax request it'll refer ajax object.

at to the lowest degree that's think means.

var objecta = class.create(); objecta.prototype = { initialize: function() { //workaround utilize = this; }, getdata: function(bounds) { //ajax info url = "http://www.data.com/"; new ajax.request(url, { method: 'get', onsuccess: function(response) { // handle response content... that.workdata(response.responsetext); //this doubt. //how access parent object without having calling "that" first? } }); }, workdata: function(data){ //do info } } var test = new objecta(); test.getdata();

well .. that not accessible within of getdata begin since it's different scope initialize. it's mutual rename this can used in inner scope contexts, , may end wanting utilize whatever this supposed in onsuccess context anyway, since asked:

onsuccess: function (response) { //this objecta }.bind(this);

in action: http://jsfiddle.net/explosionpills/hy3ca/

javascript object prototypejs

No comments:

Post a Comment