2011-03-02 60 views
0

我正在通過這個工作build-a-JavaScript-framework tutorial

爲什麼在下面的代碼是$super$parent前綴的美元符號?

dp.Class = function() { 
    return dp.oo.create.apply(this, arguments); 
} 

dp.oo = { 
    create: function() { 
    var methods = null, 
     parent = undefined, 
     klass = function() { 
      this.$super = function(method, args) { return dp.oo.$super(this.$parent, this, method, args); }; 
      this.initialize.apply(this, arguments); 
     }; 

    if (typeof arguments[0] === 'function') { 
     parent = arguments[0]; 
     methods = arguments[1]; 
    } else { 
     methods = arguments[0]; 
    } 

    if (typeof parent !== 'undefined') { 
     dp.oo.extend(klass.prototype, parent.prototype); 
     klass.prototype.$parent = parent.prototype; 
    } 

    dp.oo.mixin(klass, methods); 
    dp.oo.extend(klass.prototype, methods); 
    klass.prototype.constructor = klass; 

    if (!klass.prototype.initialize) 
     klass.prototype.initialize = function(){}; 

    return klass; 
    }, 

    mixin: function(klass, methods) { 
    if (typeof methods.include !== 'undefined') { 
     if (typeof methods.include === 'function') { 
     dp.oo.extend(klass.prototype, methods.include.prototype); 
     } else { 
     for (var i = 0; i < methods.include.length; i++) { 
      dp.oo.extend(klass.prototype, methods.include[i].prototype); 
     } 
     } 
    } 
    }, 

    extend: function(destination, source) { 
    for (var property in source) 
     destination[property] = source[property]; 
    return destination; 
    }, 

    $super: function(parentClass, instance, method, args) { 
    return parentClass[method].apply(instance, args); 
    } 
}; 

回答

3

$有一個JavaScript標識符沒有特殊的含義。它只是表示你想表示的任何內容。

2

沒有理由。可能是因爲編寫代碼的人想要明確說明父母是新的關鍵字。