This project is archived and is in readonly mode.

#490 ✓invalid
Fábio M. Costa

Native class code reduction

Reported by Fábio M. Costa | November 21st, 2008 @ 07:01 PM | in 2.0 (closed)

At the native class of mootools, the code could be smaller just by removing the lots of 'var' in there.


var Native = function(options){
 options = options || {};
 var name = options.name;
 var legacy = options.legacy;
 var protect = options.protect;
 var methods = options.implement;
 var generics = options.generics;
 var initialize = options.initialize;
 var afterImplement = options.afterImplement || function(){};
 var object = initialize || legacy;
 generics = generics !== false;

can become:


var Native = function(options){
 options = options || {};
 var name = options.name,
  legacy = options.legacy,
  protect = options.protect,
  methods = options.implement,
  generics = options.generics,
  initialize = options.initialize,
  afterImplement = options.afterImplement || function(){},
  object = initialize || legacy;

 generics = generics !== false;

Comments and changes to this ticket

  • Fábio M. Costa

    Fábio M. Costa November 22nd, 2008 @ 12:19 AM

    In fact i noticed that there are more places with unnecessary 'var'. I removed them just to see what was going to happen and i got a 0.5KB reduction on the yui-compressed-gzipped file.

    In the picture i have the moo.compressed.js which is the file without the unnecessary 'var' and the mootools.compressed.js is the original one.

    I think that's a good gain as there's nothing to lose.

  • Fábio M. Costa

    Fábio M. Costa November 22nd, 2008 @ 12:30 AM

    ermm in fact this gain is the sum of the compression without line-breaks and the removal of the unnecessary 'var' reserved word.

  • Fábio M. Costa

    Fábio M. Costa November 22nd, 2008 @ 01:03 AM

    There's still another optimization that can be done as shown here:

    http://yuiblog.com/blog/2008/02/...

    
    Element.Properties.tween = {
     set: function(options){
      var tweenString = 'tween', tween = this.retrieve(tweenString);
      if (tween) tween.cancel();
      return this.eliminate(tweenString).store(tweenString+':options', $extend({link: 'cancel'}, options));
     },
     get: function(options){
      var tweenString = 'tween';
      if (options || !this.retrieve(tweenString)){
       if (options || !this.retrieve(tweenString+':options')) this.set(tweenString, options);
      this.store(tweenString, new Fx.Tween(this, this.retrieve(tweenString+':options')));
      }
      return this.retrieve(tweenString);
     }
    };
    

    This can be applied to the morph, send and load properties as well.

  • Valerio

    Valerio January 12th, 2009 @ 04:18 PM

    • State changed from “new” to “invalid”

    We are not really interested in these kinds of micro-optimizations, as they really affect code readability.

Create your profile

Help contribute to this project by taking a few moments to create your personal profile. Create your profile »

Shared Ticket Bins

People watching this ticket

Attachments

Pages