class - JavaScript object output in console.log -


i want know console.log name of constructing function when printing object. also, effect code wise?

function f() {      this.test = 'ok'; }  var f = new f();  console.log( f ); 

the output of console.log (in chrome) is: f {test: "ok"}

where console.log f in f {test...?

if change f.constructor, f.prototype, , f.constructor random, still prints 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 still same - f {test: "ok"}

is information kept privately browser, question affect javascript code in way? is, creep during comparison or inheritance, after override constructor's prototype , constructor properties?

update

the original purpose following.

function person ( _name ) {     this.name = _name; }  function construct( _constructor, _args, _context ) {     function f () {         var context = _context || this;         return _constructor.apply( context, _args );     }      /* want have constructed object identified         _constructor , not f */     f.prototype = _constructor.prototype;      return new f(); }  function make ( _who ) {     if ( 'person' === _who ) {         /* remove first argument, who, , pass along rest.            constructors cannot called .apply have use             technique. */         return construct( person, array.prototype.slice.call( arguments, 1 ) );     } }  var dev = make( 'person', 'john doe' );  console.log( dev ); // prints `f {name: "john doe"}` 

as can see, resulting print of dev outputs f {name: "john doe"}, made me question whether may run problems later on if i'd make comparisons or inheritance instances constructed in such way.

changing f.prototype replaces content of f, not name. old prototype object still exists , reference stored internally in each instance of old f. cam check calling f.__proto__´ (deprecated) or object.getprototypeof(f).

note __proto__ accessor proterty (internally getter, not real property), cannot changed.


Comments

Popular posts from this blog

python - Subclassed QStyledItemDelegate ignores Stylesheet -

java - HttpClient 3.1 Connection pooling vs HttpClient 4.3.2 -

SQL: Divide the sum of values in one table with the count of rows in another -