changeset 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
files lightstring.js
diffstat 1 files changed, 7 insertions(+), 1 deletions(-) [+]
line wrap: on
line diff
--- a/lightstring.js
+++ b/lightstring.js
@@ -391,17 +391,23 @@ Lightstring.Connection.prototype = {
 
       var plugin = Lightstring.plugins[name];
 
+      //Namespaces
       for (var ns in plugin.namespaces)
         Lightstring.ns[ns] = plugin.namespaces[ns];
 
+      //Stanzas
       Lightstring.stanzas[name] = {};
       for (var stanza in plugin.stanzas)
         Lightstring.stanzas[name][stanza] = plugin.stanzas[stanza];
 
+      //Handlers
       for (var handler in plugin.handlers)
         this.on(handler, plugin.handlers[handler]);
 
-      this[name] = plugin.methods;
+      //Methods
+      this[name] = {}:
+      for (var method in plugins.methods)
+        this[name][method].bind(this);
 
       if (plugin.init)
         plugin.init();