+ 2

What is the "new" for?

4th Aug 2016, 10:23 AM
Sudeep Kumar Devulapally
Sudeep Kumar Devulapally - avatar
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
5th Aug 2016, 11:53 AM
wcountiss
wcountiss - avatar