I am working on a Javascript object exercise. My output is not what I expected. Please take a look at my code and give some advise. Here is the code:
function myFunction(name) {
this.name = name;
this.models = new Array();
this.add = function (brand){
this.models = brand;
};
}
var c = new myFunction ("pc");
c.add("HP");
c.add("DELL");
console.log(c.models);
The output is "DELL"
My expected output is ["HP","DELL"]
Thank you so much for your help!
this.add=[].push.bind(this.models);