+ 2
What is the "new" for?
1 Answer
+ 2
the short answer is that using the 'new' keyword does a couple of things.
1. It creates a new object
2. It makes the this variable point to the newly created object.
3. It returns the newly created object
example:
function Person (first, last) {
this.first = first;
this.last = last;
}
var bob = new Person('Bob', 'Smith');
console.log(bob.first);
// Bob
console.log(bob.last);
// Smith