You basically have this correct.
If you did this:
var myArr = [];
myArr.each = function(){ alert('hi'); };
You've just overwritten the prototype's value for .each.
Then if you did this:
delete myArr.each
You will remove that value from the instance, so that a reference to
myArr.each will find nothing, and then inspect its prototype. By deleting
the value, you are now able to switch on the prototype and, if there is no
.each on the prototype, it will be undefined.
So why not just do:
$type(myArr.prototype.each)
Because the object's prototype may not have that property, but its prototype
might, i.e. myArr.prototype.prototype.each. Or further up the chain of
inheritance - myArr.prototype.prototype.prototype.each, etc. So if you want
to get to the inherited value for something, you must remove it from the
instance and then try and reference it again.
On Sat, Feb 6, 2010 at 4:12 PM, Romansky <[email protected]> wrote:
> Thanks - Im trying to understand the code :) so please bare with me..
>
> So when core does this:
> #################
> function Class(params){
>
> if (params instanceof Function) params = {initialize: params};
>
> var newClass = function(){
> Object.reset(this);
> if (newClass._prototyping) return this;
> this._current = $empty;
> var value = (this.initialize) ? this.initialize.apply(this,
> arguments) : this;
> delete this._current; delete this.caller;
> return value;
> }.extend(this);
>
> newClass.implement(params);
>
> newClass.constructor = Class;
> newClass.prototype.constructor = newClass;
>
> return newClass;
>
> };
> #################
>
>
> This is how I understand it works:
> 1. it prototypes the newClass with the parameters we put for the
> ( newClass.implement(params); )
> 2. Then when a "new" instance is created,
> 2.1 Object.reset removes all new copies made by step 2 (now belonging
> to "this"), by this it now points the instance vars to the function
> prototype
> 2.2 Object.reset creates new object elements and arrays
> 2.3 But all other instance var types remain pointing to the prototype
>
> Is my understanding correct and I can go to sleep at last? :)
>
>
> On Feb 7, 1:17 am, Sanford Whiteman <[email protected]>
> wrote:
> > > @Sandy, how does that work? can you show an example?
> > > External link would be great also
> >
> > Like so:http://mootools.net/shell/mB3E8/
> >
> > -- Sandy
>