Well, I wasn't sure about whether this was a question or not, but some
points:

   1. IMO there are a lot of places where the real magic happens, especially
   in the entire code you supplied in point 1. What Class does is to supply a
   factory for an object. The function, when called with new, checks if the it
   has an initialize method and calls it. This is the first thing that makes
   Class important - it allows you to specify a constructor that can be
   inherited/modified.
   2. The second important part is that extend basically adds the Class
   function to the newClass prototype chain.
   3. Then, the function is passed implement on the object that you
   specified. The overloadSetter is a private mootools method, but it was
   explained in this tread:
   
http://groups.google.com/group/mootools-users/browse_thread/thread/60c355aa83a0107c?pli=1
   4. The important thing is that the function loops through the passed
   object. If any of the keys match one of Class's mutators, it passes the
   key's value it, to work it's way on the new instance (newClass).



On Sun, Dec 12, 2010 at 4:10 AM, HENG <[email protected]> wrote:

> Hi Guys:
>
> We all love the ways that created Mootools' Class, that anyone know it how
> to work? If you do not, I have some tips about that. And more, I can not
> understand all about Mootools' Class. If I have wrong tips, I am happy that
> you point it out. Thank you....
>
> 1. First of all, we know, Mootools' Class is a Function's Instance, you can
> get the source code at:
>
>
>    1. var Class = this.Class = new Type('Class', function(params){
>    2.     if (instanceOf(params, Function)) params = {initialize: params};
>    3.     var newClass = function(){
>    4.         reset(this);
>    5.         if (newClass.$prototyping) return this;
>    6.         this.$caller = null;
>    7.         var value = (this.initialize) ? this.initialize.apply(this,
>    arguments) : this;
>    8.         this.$caller = this.caller = null;
>    9.         return value;
>    10.     }.extend(this).implement(params);
>    11.     newClass.$constructor = Class;
>    12.     newClass.prototype.$constructor = newClass;
>    13.     newClass.prototype.parent = parent;
>    14.     return newClass;
>    15. });
>
> Because we create Class like that: var Mootools_Class = new Class({}), you
> can get Function' s Instance.
>
>
> 2. All Mootools' Class' Secret are at .extend(this).implement(params);This 
> code is beyond my mind to analysis it how to work.....
>
> 3.  At Mootools 1.3 stable, we know that Function.prototype.extend() , OK,
> now, var newClass().extend(this) ; It will make newClass has the same
> prototype as Class type,
>
> 4. Now, magic happends, the source has Class.implement('implement',
> implement.overloadSetter()); ,And this method just defined by Class.js,
> code is as follow:
>
>
>    1. var implement = function(key, value, retain){
>    2.     if (Class.Mutators.hasOwnProperty(key)){
>    3.         value = Class.Mutators[key].call(this, value);
>    4.         if (value == null) return this;
>    5.     }
>    6.     if (typeOf(value) == 'function'){
>    7.         if (value.$hidden) return this;
>    8.         this.prototype[key] = (retain) ? value : wrap(this, key,
>    value);
>    9.     } else {
>    10.         Object.merge(this.prototype, key, value);
>    11.     }
>    12.     return this;
>    13. };
>
> 5. Now, .extend(this).implement(params); , Method  .implement(params); means
> that, it will run the implements function above, and pass our defined
> params to implements function.
>
> 6. The key statement in implement Function above are:
>
>     value = Class.Mutators[key].call(this, value);
>
>     this.prototype[key] = (retain) ? value : wrap(this, key, value);
>
> The Former means that, it will handler the Class.Mutators, in Mootools,
> they are Extends and Implements.
>
> The latter means that, when pass key word just like parent (this is the
> reason why we can use this.parent() ), it will make a reference to
> parent's prototype....
>
> 7. Ok, I just understand just now, and go on, I am very confuse about how
> Mootools' Class work....
>
> 8. Questions:
>
> 8.1. That anyone can give me a list about Mootools Class prototype, just
> like: $caller, $owner, $current, $prototyping, $constructor, $name,
> $origin, $hidden, parent, what are they standing for? and what are the
> meaning of those words in mootools?
>
> 8.2. Who can give me a list that how a Mootools' class Extends from a
> Parent class ? I can not catch it clearly, even I done it in Firebug again
> and again.
>
> 8.3. Mootools' class is hard to get is its Prototype clearly. That anyone
> know it clearly, send me some tips, and I really thank you...
>
> 8.4. We know, Mootools now is 1.3 version, That anyone know where to get
> the old version before 1.3. for example, Mootools 1.1, Mootools 1.0, and
> Mootools 0.9.... Thank you....
>
>
>
> Reference:
>
> Thank you the guys below, your blog is benifited to me.....
>
> [1]:
> http://keetology.com/blog/2009/07/23/up-the-moo-herd-iii-its-classy-not-classic
> [2]:
> http://keetology.com/blog/2009/10/27/up-the-moo-herd-iv-theres-a-class-for-this
> [3]:
> http://keetology.com/blog/2009/07/20/up-the-herd-ii-native-flora-and-fauna
>
>
> --
> --------------------------------------------------------------------
> HengZhou
>
> Web Frontend Engineer.....Baidu.......
> ---------------------------------------------------------------------
> --
>
>


-- 
Arieh Glazer
אריה גלזר
052-5348-561
http://www.arieh.co.il
http://www.link-wd.co.il

Reply via email to