[svn openjsan.org] [467] I started on this a while ago.

0 views
Skip to first unread message

ca...@geeknest.com

unread,
Dec 20, 2005, 6:29:01 PM12/20/05
to jsan-...@googlegroups.com
Revision: 467
Author: theory
Date: 2005-12-20 18:28:55 -0500 (Tue, 20 Dec 2005)

Log Message:
-----------
I started on this a while ago. I dunno if I will ever release it, but at least
now it is here so that I can hack on it in the future if I want to.

Added Paths:
-----------
users/theory/Method/
users/theory/Method/trunk/
users/theory/Method/trunk/lib/
users/theory/Method/trunk/lib/Method.js
Added: users/theory/Method/trunk/lib/Method.js
===================================================================
--- users/theory/Method/trunk/lib/Method.js 2005-10-25 17:27:15 UTC (rev 466)
+++ users/theory/Method/trunk/lib/Method.js 2005-12-20 23:28:55 UTC (rev 467)
@@ -0,0 +1,59 @@
+Method = function () {};
+
+/*
+
+=head2 Method.bind( object )
+
+The C<bind()> function provides the ability ability to create a closure over a
+method useful for passing to C<setTimeout()>.
+
+ var obj = new Some.Class();
+
+ var closure = Method.bind(obj.someMethod, obj);
+ window.setTimeout( closure, 10 );
+
+ window.setTimeout(object.someMethodbind.bind(obj));
+ window.setTimeout(function () { obj.someMethod() });
+
+=cut
+
+*/
+
+Method.closure = function (fn, obj) {
+ return function () { fn.apply(obj, arguments) };
+};
+
+Method.bind = Method.closure;
+
+/*
+
+=head2 Method.continuation( object )
+
+The C<continuation()> function provides the ability ability to create a
+continuation over a method. This can be useful if you need to pass the same
+arguments to a method call over and over again.
+
+ var obj = new Some.Class();
+
+ var cont = Method.continuation(obj.someMethod, obj, 1, 2, 3);
+ cont(4, 5); // Calls obj.someMethod(1, 2, 3, 4, 5);
+
+=cut
+
+*/
+
+Method.continuation = function (fn, obj) {
+ var args = [];
+ for (var i = 2; i < arguments.length; i++) {
+ args.push(arguments[i]);
+ }
+ return function () {
+ var pass = args.slice(0, args.length);
+ for (var j = 0; j < arguments.length; j++) {
+ pass.push(arguments[j]);
+ }
+ fn.apply(obj, pass);
+ };
+}
+
+// PHP: Need shared library built.
\ No newline at end of file

Reply all
Reply to author
Forward
0 new messages