Suppose if I define a class in file1.js
function Customer(){ this.name="Jhon"; this.getName=function(){ return this.name; }; };
Now, if I want to create a Customer object in file2.js
var customer=new Customer(); var name=customer.getName();
I get an exception: Customer is undefined, not a constructor.
But when I create a customer object in file2.js and pass it to file1.js, then it works.
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();
but I want to create a customer object in file1.js using the new Customer (). How can I achieve this?
Tarak
source share