comparison lightstring.js @ 56:1d4b844586f6

Bind methods so Lightstring.Connection.plugin.method works with the correct context.
author Sonny Piers <sonny.piers@gmail.com>
date Wed, 01 Feb 2012 15:46:57 +0100
parents aaad98b33f86
children 91f18fdc0e2c
comparison
equal deleted inserted replaced
55:aaad98b33f86 56:1d4b844586f6
389 if (!(name in Lightstring.plugins)) 389 if (!(name in Lightstring.plugins))
390 continue; //TODO: throw an error? 390 continue; //TODO: throw an error?
391 391
392 var plugin = Lightstring.plugins[name]; 392 var plugin = Lightstring.plugins[name];
393 393
394 //Namespaces
394 for (var ns in plugin.namespaces) 395 for (var ns in plugin.namespaces)
395 Lightstring.ns[ns] = plugin.namespaces[ns]; 396 Lightstring.ns[ns] = plugin.namespaces[ns];
396 397
398 //Stanzas
397 Lightstring.stanzas[name] = {}; 399 Lightstring.stanzas[name] = {};
398 for (var stanza in plugin.stanzas) 400 for (var stanza in plugin.stanzas)
399 Lightstring.stanzas[name][stanza] = plugin.stanzas[stanza]; 401 Lightstring.stanzas[name][stanza] = plugin.stanzas[stanza];
400 402
403 //Handlers
401 for (var handler in plugin.handlers) 404 for (var handler in plugin.handlers)
402 this.on(handler, plugin.handlers[handler]); 405 this.on(handler, plugin.handlers[handler]);
403 406
404 this[name] = plugin.methods; 407 //Methods
408 this[name] = {}:
409 for (var method in plugins.methods)
410 this[name][method].bind(this);
405 411
406 if (plugin.init) 412 if (plugin.init)
407 plugin.init(); 413 plugin.init();
408 } 414 }
409 }, 415 },