I want to know where the .log console gets the name of the build function when printing the object. Also, does this really affect any code?
function F() { this.test = 'ok'; } var f = new F(); console.log( f );
Output console.log file (in Chrome): F {test: "ok"}
Where does the .log console get F in F {test... ?
If I change F.constructor , F.prototype and F.constructor to something random, it still prints the original F :
function G() { this.fail = 'bad'; } function F() { this.test = 'ok'; } F.prototype = G; F.constructor = G; var f = new F(); console.log( f );
The output is the same - F {test: "ok"}
Is this information just confidential in the browser, my question is, does it affect JavaScript code? That is, will it creep during comparison or inheritance after I override the properties of the prototype and constructor ?
UPDATE
The original goal was to do the following.
function Person ( _name ) { this.name = _name; } function Construct( _constructor, _args, _context ) { function F () { var context = _context || this; return _constructor.apply( context, _args ); } F.prototype = _constructor.prototype; return new F(); } function Make ( _who ) { if ( 'person' === _who ) { return Construct( Person, Array.prototype.slice.call( arguments, 1 ) ); } } var dev = Make( 'person', 'John Doe' ); console.log( dev );
As you can see, the resulting dev response outputs F {name: "John Doe"} , which made me wonder if I could run into problems later if I wanted to do comparisons or inheritance with instances constructed in this way.