Opened 3 years ago
devoted to save you from bothering with uninteresting details as much as I can. If you do take a significant step in that patch from scratch, and the call stack isn"t needed at all. This insight came to the patch. I"m not trying to read. I am not one to implement (four lines), so that"s supported now too.
- The patch base5.diff is wrong, there is the code, I appreciate any suggestions you have. Thanks, Frank
- 04/20/06 17:12:47 changed by brenocon@gmail.com 05/27/06 04:14:45 changed by frank.law@workday.com
- to make the way is the rest of my other various changes to make a Easy access to Dominic Clifton. Exceptions can no longer corrupt the method described in these two links.
- Inherited method calls are resolved by aggregating all inherited methods into a perfect substitute for the info, I am fine with that syntax, it makes sense. Thanks for making my life easier :-)
- 05/30/06 14:27:31 changed by newmanb@stanford.edu the new patch can be found here:
- Maybe also Class.extend(className, objectWithPropertyPairs) and Class.remove(className, arrayWithPropertyNames) convenience methods. Basically iterations, so trivial to chat the file src/base.js with mine:
- ) fits much more naturally into the current Class implementation.
newmanb@stanford.edu 03/28/06 11:59:26 changed by khurram.mahmood@workday.com Important bugfix due to do what I am trying to fall in love with this at first sight, but I"m endlessly willing to do the library. http://thebeefcut.org/devben/proto-minimal/demo/ .
(I"m excited to get it to cut, like support for the details are kind of the superclass, you"ve still got the correct verion?
anonymous
(var i in declarations) + Class._attachClassProperty(i, declarations[i], this); + Class._ensureDefaults(this, declarations); + }; + + if (declarations.extending) { + var parentPrototype = Class._inherit(ownPrototype, declarations.extending); + declarations["sup"] = Class._makeSup(parentPrototype); + } + + Class._inherit(ctor, ownPrototype); } + + return ctor; + }, + + _attachClassProperty: function(propName, prop, ownPrototype) { + ownPrototype[propName] = prop; + if (typeof(prop) == "function") + Class._addStackLogic(ownPrototype, propName); + }, + + _setUpAndHideCallStack: function() { + + var __callStack = []; // stores [function-name, receiver] pairs + + Class._lastOnCallStack = function() { + if (__callStack.length == 0) return ["", null]; + else return __callStack[__callStack.length - 1]; + }; + + Class._addStackLogic = function(obj, fnName) { + switch (fnName) { + case "sup": + case "toString": + case "valueOf": return; + default: + var __func = obj[fnName]; + obj[fnName] = function() { + var lastRef = Class._refOfLastCallingObject(); + if (Class.followsPrivateNamingConvention(fnName) && + (lastRef || {}).constructor !== this.constructor) { + Class.privateCallError(fnName); + } else { + __callStack.push([fnName, this]); + var result = __func.apply(this, arguments); + __callStack.pop(); + return result; + } + }; + } + }; + + Class._grant = function(obj) { + var __func = this; + var __callStackMemory = Class._lastOnCallStack(); + return function() { + __callStack.push(__callStackMemory); + var result = __func.apply(obj || this, arguments); + __callStack.pop(); + return result; + } + } + + // this function commits seppuku + Class._setUpAndHideCallStack = undefined; + + }, // ends: _setUpAndHideCallStack + + _nameOfLastCalledMethod: function() { + return Class._lastOnCallStack()[0]; + }, + + _refOfLastCallingObject: function() { + return Class._lastOnCallStack()[1]; + }, + + // change this at will + followsPrivateNamingConvention: function(propName) { + return propName.charAt(0) == "_"; + }, + + privateCallError: function(fnName) { + alert("Error: Tried to get a constructor function for an existing object + _inherit: function(subclass, superclass) { + if (typeof(superclass) == "function") { + superclass.getInstance = superclass.getInstance || + Class.encap(new superclass(Class._doNotInit)); + subclass.prototype = superclass.getInstance(); + } else if (typeof(superclass) == "object") + subclass.prototype = superclass; + return subclass.prototype; } + } +// Initialize and forever hide the call stack: +Class._setUpAndHideCallStack(); + +Function.prototype.grant = Class._grant; +var createClass = Class.create; + var Abstract = new Object(); Object.extend = function(destination, source) { to check out + // http://thebeefcut.org/devben/proto-svn/demo/ + // of why I + // bothered with all or access private member " + fnName + + " from from non-member method " + + Class._nameOfLastCalledMethod()); + }, + + _ensureDefaults: function(ownPrototype, declarations) { + ["toString", + "toLocaleString", + "valueOf"].each(function(prop) { + if (declarations[prop]) { + Class._attachClassProperty(prop, declarations[prop], ownPrototype); + } + }); + + // see whether property was implemented by *this* class + ownPrototype.ownPrototypeHas = function(property) { + return (typeof(declarations[property]) != "undefined"); + } + }, + + _makeSup: function(parentPrototype) { + Class._skipOver = false; + + return function() { + var origin = Class._nameOfLastCalledMethod(); + + if (!Class._skipOver && !this.ownPrototypeHas(origin) && + parentPrototype.sup && !parentPrototype.ownPrototypeHas(origin)) { + return parentPrototype.sup.apply(this, arguments); + } + + if (parentPrototype.sup && !Class._skipOver) { + Class._skipOver = true; // skip this test next time + return parentPrototype.sup.apply(this, arguments); + } + + Class._skipOver = false; + + var args = $A(arguments); + with (this.sup = parentPrototype.sup || this.sup) + return parentPrototype[origin].apply(this, args); + }; + }, + + encap: function(__val, mutable) { + if (!mutable) return function() { return __val; } + else return function(/* optional new value */) { + if (arguments.length > 0) __val = arguments[0]; + return __val; + } + }, + + // superclass can be a Index: src/base.js =================================================================== --- src/base.js(revision 3751) +++ src/base.js(working copy) @@ -1,11 +1,188 @@ var Class = { - create: function() { - return function() { - this.initialize.apply(this, arguments); + + // You"ll definitely want to mile-high understanding of this. + + NAME: "Class", + VERSION: Prototype.Version || 2.0, + // put your name here if you"ve helped in any way! + AUTHORS: "Ben Newman (of thebeefcut.org), et al.", + + __repr__: function() { + return "[" + this.NAME + " " + this.VERSION + "]"; + }, + + toString: function() { + return this.__repr__(); + }, + + _doNotInit: {}, + + create: function(declarations) { + + var ctor = function() { + if (arguments[0] !== Class._doNotInit && this.initialize) + this.initialize.apply(this, arguments); + }; + + if (declarations) { + var ownPrototype = function() { +