2011-03-02 11 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

理由はありません。おそらくそのコードを書いた人は、スーパー&の親が新しいキーワードであることを明らかにしたかったからでしょう。

関連する問題