I'm quite new to both JavaScript OOP and require.js
I'm learning to use require.js to improve application scalability, I tried to google for articles but not really understand because of my poor JavaScript background.
I have come up with this coding.
employee.js
define([], function() {
function Employee(empName) {
return {
_empName: empName,
getEmployeeName: function() {
return _empName;
}
}
}
});
customer.js
define([], function() {
function Customer(customerName) {
this._customerName = customerName;
this.getCustomerName = function() {
return this._customerName;
}
}
return(Customer);
});
I have tried 2 different styles of coding for Employee and Customer prototype.
main.js
require(['customer', 'employee'], function(Customer, Employee) {
c = new Customer('Boy');
console.log('Customer name is ' + c.getCustomerName());
e = new Employee('Mike');
console.log('Employee name is ' + e.getEmployeeName());
});
This is the result I got.
My question is that coding in customer.js is only the way to declare prototype for using with require.js ?
My understanding is that require.js always and only inject dependencies as class (not instance) right?
Helping me by answer these 2 simple questions will help me to move along to the next step of my learning, any suggested articles would be really appreciated, (I really have no ideas which specific topics to search for).
Thanks