Aptana Studio3を使用してJavascriptOOPをコーディングしています。「new」と「this」を使用してクラスとオブジェクトを作成していますが、IDEオートコンプリートがオブジェクトのプロパティとメソッドを認識しないため、非常に煩わしいです。
リテラル表記に変更すると、IDEはオブジェクトを認識してオートコンプリート機能を有効にしますが、同じ機能を維持したままコードをリテラル表記に変換できません。
私はサンプルを書きました、私が通常書く方法。
var ClassPerson=function(name,lastName){
//initialize stuff here
alert(name + ' was just created now!');
var time=setInterval( function(){getOlder(1);} ,(1000*60*60*24*365));
//public properties
this.name=name;
this.lastName=lastName;
//private properties
var age=0;
var weight=3;
var parent=this; //reference to 'this' of this object, not the caller object.
//public methods
this.speak=function(text){
alert(text);
}
this.walk=function(steps){
weight=weight-(0.05*steps);
}
this.eat=function(kcal){
weight=weight+(kcal/2);
}
//private methods
function getOlder(years){
age=age+years;
}
}
var me = new ClassPerson('Justin','Victor');
me.speak( me.name );
me.eat(2500);
誰かがこれをリテラルに変換できれば、それがどのように機能するかを理解できるかもしれません。