1

I'm starting with JavaScript and studied the following code. What does the new operater do? Is not the canvas.js calling itself and creates a canvas?

main.js

(function(){
     new display.Canvas();

})();

canvas.js

(function(){

var Canvas = display.Canvas = function() {

    this.createCanvas();

};
})();
poppel
  • 1,543
  • 4
  • 17
  • 22

1 Answers1

2

Douglas Crockford has a good article on how "new" works.

In the example you give, the code in canvas.js (assuming the display.canvas should actually be display.Canvas) is defining a function for how a new canvas is created. The main.js code uses that function to create a Canvas.

Dan Wich
  • 4,923
  • 1
  • 26
  • 22