public
Fork of nathansobo/screw-unit
Description: A Javascript BDD Framework with nested describes, a convenient assertion syntax, and an intuitive test browser. - this fork is an attempt to add mocking (Ajax mocking is for prototype)
Homepage:
Clone URL: git://github.com/tobowers/screw-unit.git
screw-unit / lib / jquery.fn.js
100644 29 lines (29 sloc) 0.781 kb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
(function($) {
  $.fn.fn = function() {
    var self = this;
    var extension = arguments[0], name = arguments[0];
    if (typeof name == "string") {
      return apply(self, name, $.makeArray(arguments).slice(1, arguments.length));
    } else {
      $.each(extension, function(key, value) {
        define(self, key, value);
      });
      return self;
    }
  }
  function define(self, name, fn) {
    self.data(namespacedName(name), fn);
  };
  function apply(self, name, args) {
    var result;
    self.each(function(i, item) {
      var fn = $(item).data(namespacedName(name));
      if (fn) result = fn.apply(item, args)
      else throw(name + " is not defined");
    });
    return result;
  };
  function namespacedName(name) {
    return 'fn.' + name;
  }
})(jQuery);