javascript - How to detect if a function inside a constructor was called as an constructor -


so have created function checks if called constructor:

{     this.x = function() {         if (!this instanceof x) {             return new x;         }         ...     } } 

but want have function inside should called constructor

{     this.x = function() {         if (!this instanceof x) {             return new x;         }         this.y = function(){             if (!this instanceof y) {                 return new y;             }          }      } } 

however, when try this, typeerror:

uncaught typeerror: right-hand side of 'instanceof' not object 

how can check if function y called constructor?

thanks in advance


Comments

Popular posts from this blog

service - Android MediaPlayer calls onCompletion before it already finished -

javascript - Training Neural Network to play flappy bird with genetic algorithm - Why can't it learn? -

javascript - Create a stacked percentage column -