public
Description: A jQuery plugin for Morphic programming
Clone URL: git://github.com/nkallen/effen.git
the result is the last item in the collection
Nick Kallen (author)
Sun Mar 09 18:32:58 -0700 2008
commit  51842de47f71869898e0dc58617caea4b1073f28
tree    536413e24540b072ca3f890dfbd5cd0249e2d96e
parent  d79e63f1ef66264971e92bd9115ec5e17d0be672
...
28
29
30
 
 
 
 
 
 
 
31
32
33
...
28
29
30
31
32
33
34
35
36
37
38
39
40
0
@@ -28,6 +28,13 @@
0
             element.fn('name1').should("==", 1);
0
             element.fn('name2').should("==", 2);
0
           });
0
+ it("applies bound functions to each item in a collection", function() {
0
+ var elements = $("<div></div>").add($("<div></div>"));
0
+ var i = 0;
0
+ elements.fn({ call: function() { i++ } });
0
+ elements.fn('call');
0
+ i.should("==", 2);
0
+ });
0
         });
0
       });
0
     </script>
...
14
15
16
17
18
19
20
21
22
 
 
 
 
 
 
 
 
 
 
23
24
25
...
14
15
16
 
 
 
 
 
 
17
18
19
20
21
22
23
24
25
26
27
28
29
0
@@ -14,12 +14,16 @@
0
   function define(self, name, fn) {
0
     self.data(namespacedName(name), fn);
0
   };
0
- function apply(self, name, arguments) {
0
- var fn = self.data(namespacedName(name));
0
- if (fn)
0
- return fn.apply(self, arguments);
0
- else
0
- throw(name + " is not defined");
0
+ function apply(self, name, args) {
0
+ var result;
0
+ self.each(function(i, item) {
0
+ var fn = $(item).data(namespacedName(name));
0
+ if (fn)
0
+ result = fn.apply(item, args);
0
+ else
0
+ throw(name + " is not defined");
0
+ });
0
+ return result;
0
   };
0
   function namespacedName(name) {
0
     return 'fn.' + name;

Comments

    No one has commented yet.