私は今file1.js別のjsファイルでjavascriptクラスをインスタンス化する方法は?
function Customer(){
this.name="Jhon";
this.getName=function(){
return this.name;
};
};
でクラスを定義する場合、私は、私は例外取得していますfile2.js
var customer=new Customer();
var name=customer.getName();
でCustomerオブジェクトを作成する場合としますCustomer is undefined, not a constructor.
しかし、私はfile2.jsで顧客オブジェクトを作成し、それをfile1.jsに渡してから作業します。
file1.js
function Customer(){
this.name="Jhon";
this.getName=function(){
return this.name;
}
}
function customer(){
return new Customer();
}
file2.js
var customer=customer();
var name=customer.getName();
しかし、新しいCustomer()を使用してfile1.jsに顧客オブジェクトを作成したいとします。どうすればそれを達成できますか?
ああ、JSをOOP言語として使用しようとしていることの喜び。 – NullUserException