Confusing JavaScript statement: "var x = new this();"

Viewed 10544

I thought I understood the concept of the JavaScript prototype object, as well as [[proto]] until I saw a few posts regarding class inheritance.

Firstly, "JavaScript OOP - the smart way" at http://amix.dk/blog/viewEntry/19038

See the implementation section:

var parent = new this('no_init');

And also "Simple JavaScript Inheritance" on John Resig's great blog.

var prototype = new this();

What does new this(); actually mean?

This statement makes no sense to me because my understand has been that this points to an object and not a constructor function. I've also tried testing statements in Firebug to figure this one out and all I receive is syntax errors.

My head has gone off into a complete spin.

Could someone please explain this in detail?

8 Answers

A simpler code explaination:

class User {
  constructor() {
    this.name = '';
    this.age = '';
  }
  static getInfo() {
    let user = new this();
    console.log(user);
  } 
}

User.getInfo()

Output:

Object {
  age: "",
  name: ""
}
Related