Friday, July 18th, 2008
Semantic Constructors
-
-
Class.create = (function(original) {
-
var fn = function() {
-
var result = original.apply(null, arguments);
-
result.toString = function() { return result.prototype.initialize.toString() };
-
return result;
-
};
-
fn.toString = function(){ return original.toString() };
-
return fn;
-
})(Class.create);
-
This monkey patch by kangax allows you to get sense from inspecting a constructor setup via Prototype.
His code changes a simple person class from:
-
-
Person + ''; // "function klass() { this.initialize.apply(this, arguments); }"
-
too:
-
-
Person + ''; // "function (name) { this.name = name; }"
-
If you want more help with Prototype and Script.aculo.us you can check out their newly changed support list.








Leave a comment