Encountering an error while attempting to initiate an ajax request within a class from another class function has left me puzzled. This issue can be observed in the Firefox console using the following examples:
https://jsfiddle.net/d2o1d0eu/
http://codepen.io/anon/pen/dGwwKG
var MyClass = new Class({
initialize: function(options){
this.my_request = new Request({
url: '/echo/html/',
method: 'post',
onSuccess: function(resp) {
alert(resp);
}
});
},
request: function(param){
this.my_request.send('html='+param);
}
});
var MySecondClass = new Class({
Implements: [Options],
options: {
first_class: {}
},
initialize: function(options){
this.setOptions(options);
this.options.first_class.request('internal'); // error
},
request: function(param){
this.options.first_class.request(param);
}
});
var unknown_name = new MyClass();
// unknown_name.request('unknown_name test'); // ok
var test = new MySecondClass({
'first_class': unknown_name
});
// test.request('second class test'); // error
If you have any suggestions or insights on this matter, please feel free to share. Thank you.