Supponiamo che se definisco una classe in file1.jsCome istanziare una classe javascript in un altro file js?
function Customer(){
this.name="Jhon";
this.getName=function(){
return this.name;
};
};
Ora, se voglio creare un oggetto Cliente file2.js
var customer=new Customer();
var name=customer.getName();
io sono sempre un'eccezione: Customer is undefined, not a constructor.
Ma quando creo un oggetto cliente in file2.js e lo passo a file1.js quindi funziona.
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();
ma voglio creare un oggetto cliente in file1.js utilizzando nuovi clienti(). Come posso ottenerlo?
Ah, le gioie di provare a utilizzare JS come linguaggio OOP. – NullUserException