Skip to content

Instantly share code, notes, and snippets.

@nijikokun
Created November 4, 2013 06:22
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save nijikokun/7298768 to your computer and use it in GitHub Desktop.
Save nijikokun/7298768 to your computer and use it in GitHub Desktop.
Observable using jquery
var observe = function (obj) {
var pojo = jQuery({});
jQuery.each({ 'on': 0, 'one': 0, 'off': 0, 'trigger': 'emit' }, function (method, alias) {
obj[alias ? alias : method] = function () {
pojo[method].apply(obj, arguments);
return obj;
}
});
return obj;
};
@nijikokun
Copy link
Author

You would use it like so:

var method = function () {
  var self = this;

  observe(self);

  self.on('event', function () {
    ...
  });
};

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment