Pro Javascript Design Patternsの第3章にあるこれらのサンプルに欠陥があることを誰もが確かめることができますか?もしそうなら、JavaScriptの意図的な目的を達成するには、ありがとう。Pro Javascriptデザインパターンの正誤情報?
var Class = (function() {
// Constants (created as private static attributes).
var UPPER_BOUND = 100;
// Privileged static method.
this.getUPPER_BOUND() {//sic
return UPPER_BOUND;
}
...
// Return the constructor.
return function(constructorArgument) {
...
}
})();
/* Usage. */
Class.getUPPER_BOUND();
/* Grouping constants together. */
var Class = (function() {
// Private static attributes.
var constants = {
UPPER_BOUND: 100,
LOWER_BOUND: -100
}
// Privileged static method.
this.getConstant(name) {//sic
return constants[name];
}
...
// Return the constructor.
return function(constructorArgument) {
...
}
})();
/* Usage. */
Class.getConstant('UPPER_BOUND');
Javascriptは古典的ではありません。プロトタイプや他の言語を使用する方法を学んでください。 JS:あなたが読んでいるものではなく、良い部分を読んでください。 –
@GlennFerrieLiveは主にレコードのために、私はプロトタイプの継承メカニズムを知っていましたが、そうでないと仮定した理由を理解することができます – Joffer