ok so i built a dynamic content swapping system using mootools for my website and I’m having trouble with one aspect about it. When it pulls the new content off the server it also gets a snippet of code which is to be executed by the Type Function
setContent: function(content) {
var self = this;
window.history.pushState({x: 0}, "x", content[0].toLowerCase());
var mainField = $('meat');
mainField.set('html', content[1]);
if(content[2] != false) {
var functionn = Function(content[2]);
functionn();
}
},
Now in this situation im trying to execute a method in the class:
addLink: function(item) {
var self = this;
var object = $(item);
self.menus.include(item);
object.addEvent('click', function(event) {
event.stop();
});
},
by sending this to the set content method to be executed:
self.addLink('#order');
now when I try it out i get this error:
Uncaught TypeError: Object [object Window] has no method 'addLink'
I guess
selfrefers towindowrather than to your class, see the example at http://mootools.net/docs/core/Types/Function#Function:bind. Usebind()to bindthisto your class and then usethisin your server reply.