Thanks for the confirmation!
But I am not trying to do anything with Object.reset in my code, I am
actually after the implementation of Class, it looks like if we use:
MyClass = new Class({
myHash: new Hash()
})
//When when go ahead and do this:
myClass = new MyClass();
myClass2 = new MyClass();
//And we do this now:
myClass.myHash.set('test','testing');
//This will now work:
myClass2.myHash.get('test'); // will return 'testing'
IMO this is either an error in documentation or an error in the
implementation of Class?
This is what I am after..
I have logged a lighthouse ticket and $unlink was suggested to be used in
Object.reset, IMO this would be more logical and intuitive than whats
happening right now
On Mon, Feb 8, 2010 at 7:26 PM, Aaron Newton <[email protected]> wrote:
> 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
>>
>
>
--
---
"Make everything as simple as possible, but not simpler."
- Albert Einstein