Looking at the definition of a square below, I get the In the browser (Chrome), we will get the following: Fun should you ask by custom Using Who will give us: RangeError: maximum call stack size When trying to see what the object is, to see what qualities are there.
var person = (function () {function person (name, age) {this.name = name; this.age = age;} Person.prototype .intpect = function () {console .log (this);}; return person;}) (); Var radek = new person ("Radek", 28); Radek.inspect ();
person {name: "rack", Age: 28, inspection: function}
inspection () When we try to inspect them, we will be called upon to define the tasks defined on the items being inspected. This leads to a recursive with no end in our case.
util module to reduce the problem while preserving the name is giving additional options
customInspect in
inspection < / Code>:
var util = require ("use"); Var person = (function () {function person (name, age) {this.name = name; this.age = age;} person.prototype.inspect = function () {console.log (util.inspect (this, { 'Custom inspect': false}})}} return person;}) var radek = new person ("Radek", 28); radek.inspect ();
{name: 'Radek', age: 28}
No comments:
Post a Comment