Author: hannes
Date: 2009-03-20 14:28:18 +0100 (Fri, 20 Mar 2009)
New Revision: 9550
Modified:
helma-ng/trunk/modules/helma/filestore.js
helma-ng/trunk/modules/helma/functional.js
Log:
Rename functions in helma/functional, backpedal from previous commit, and add/fix doc comments
Renamed partial() to bindArguments(), while bind() is now bindThisObject(). Also, do not ignore the this-object in partial()/bindArguments(), the previous commit was totally bogus.
Details at http://dev.helma.org/trac/helma/changeset/9550
Modified: helma-ng/trunk/modules/helma/filestore.js
===================================================================
--- helma-ng/trunk/modules/helma/filestore.js 2009-03-20 13:28:16 UTC (rev 9549)
+++ helma-ng/trunk/modules/helma/filestore.js 2009-03-20 13:28:18 UTC (rev 9550)
@@ -71,9 +71,9 @@
var typeName = constructor.name;
// install filter, all, and get methods on constructor
- constructor.list = partial(list, typeName);
- constructor.all = partial(getAll, typeName);
- constructor.get = partial(get, typeName);
+ constructor.list = bindArguments(list, typeName);
+ constructor.all = bindArguments(getAll, typeName);
+ constructor.get = bindArguments(get, typeName);
constructor.store = this;
// add class to registry
typeRegistry[typeName] = constructor;
@@ -105,8 +105,8 @@
var proto = constructor.prototype;
for (var [key, field] in fields) {
- proto.__defineSetter__(key, partial(setter, key, field));
- proto.__defineGetter__(key, partial(getter, key, field));
+ proto.__defineSetter__(key, bindArguments(setter, key, field));
+ proto.__defineGetter__(key, bindArguments(getter, key, field));
}
proto.__defineGetter__("_type", function() {
Modified: helma-ng/trunk/modules/helma/functional.js
===================================================================
--- helma-ng/trunk/modules/helma/functional.js 2009-03-20 13:28:16 UTC (rev 9549)
+++ helma-ng/trunk/modules/helma/functional.js 2009-03-20 13:28:18 UTC (rev 9550)
@@ -1,27 +1,42 @@
-export('partial', 'bind');
+export('bindArguments', 'bindThisObject');
/**
- * Simple reimplementation of Mochikit partial()
+ * Return a function wrapper around another function that binds
+ * some or all arguments of the original function. The argument
+ * list of the returned function corresponds to the arguments
+ * of the original function that are not covered by the pre-defined
+ * arguments.
+ *
+ * This is a simple reimplementation of Mochikit partial()
+ *
+ * @param fn {function} a function
+ * @param args
+ * @return {function} a function with bound arguments
*/
-function partial(fn /*, arg, ... */) {
+function bindArguments(fn /*, arg, ... */) {
if (typeof(fn) != "function")
- throw "fn not a function in functionUtils.partial: " + fn;
+ throw "Not a function: " + fn;
var slice = Array.prototype.slice;
var pre_args = slice.call(arguments, 1);
return function() {
var args = pre_args.concat(slice.call(arguments));
- return fn.apply(null, args);
+ return fn.apply(this, args);
}
}
/**
- * Create a wrapper for a function that always binds an object to "this"
- * even if it is called as global function.
+ * Create a wrapper for a function that always binds an object to
+ * the this-object even if it is called as global function or on
+ * another this-object.
+ *
* @param fn {function} a function
* @param obj {Object} the object to bind to the "this" object
+ * @return a function with bound this object
*/
-function bind(fn, obj) {
+function bindThisObject(fn, obj) {
+ if (typeof(fn) != "function")
+ throw "Not a function: " + fn;
return function() {
return fn.apply(obj, arguments);
}
lmpx.com only provides a reader for public news (NNTP) servers. It is not
affiliated with the servers or forums shown here and is not responsible for
the content of articles, which is written by their respective authors.