2011-07-17 5 views

答えて

9

prototypebackbone使用initialize代わりにかかわらず)が、昔ながらのjavascript

6

エグゼクティブ・サマリーでinit機能について特別なものは何もありません。他の人のようにが言う - initプロパティは魔法ではありませんJavascript。

長期ストーリー:Javascriptオブジェクトは単にキー値ストレージに過ぎません。オブジェクトをインスタンス化すると、ほとんど空になります。コンストラクタのプロトタイプからいくつかのプロパティを継承するだけです。これは、クロームインスペクタからサンプルダンプです:

> obj = {} 
Object 
+-__proto__: Object 
|-__defineGetter__: function __defineGetter__() { [native code] } 
|-__defineSetter__: function __defineSetter__() { [native code] } 
|-__lookupGetter__: function __lookupGetter__() { [native code] } 
|-__lookupSetter__: function __lookupSetter__() { [native code] } 
|-constructor: function Object() { [native code] } 
|-hasOwnProperty: function hasOwnProperty() { [native code] } 
|-isPrototypeOf: function isPrototypeOf() { [native code] } 
|-propertyIsEnumerable: function propertyIsEnumerable() { [native code] } 
|-toLocaleString: function toLocaleString() { [native code] } 
|-toString: function toString() { [native code] } 
|-valueOf: function valueOf() { [native code] } > obj = {} 

- あなたが見ることができるように、リストにはinitはありません。 initに最も近いのはconstructorとなります。 here

関連する問題