How many ways do we have to apply a method in an object to another object in javascript? code example
Example 1: function inside object javascript
var obj = {
func: function(a, b) {
return a * b;
}
};
obj.func(3, 6); // 18
Example 2: adding function to objects js
var myObj = {
myFunc: function(param){
//do stuff
}
}
Example 3: js create object with properties
function Car(make, model, year) {
this.make = make;
this.model = model;
this.year = year;
}