javascript - this.property returns undefined in nodejs -


I am writing in an app node and I am walking in something weird.

To modify that object I have to object in the function with the call () method when I return the function inside the console.log (function), this object fixes, however when I open the console I try to do this.foo or try to modify the object, so it is undefined. Update: I also have to mention that I pass this function in an object because I have to inject the function into another function. (More specific, I am trying to work, maybe it is also part of the problem.

  var obj = {name: "John", age: 23}; var functions = { Up: function () {/ * do stuff * /}, below: function () {/ * stuff * / functions.up.call (obj); up: function () {console.log (this); / / returns {Name: "John", Age: 23} console.log (this.name); // Returns unsupported., Wif = "jenny"; // nothing does}  

though If I set properties with '_' then they exist but when I call console.log (this), then

  above: Funk Nothing (console). {This. _wife = "jenny"; // does not consume anything. Log (this._wife); // "jenny" brings console.log (this); // still returned {name: "John", Age: 23}}  

I have tried to use all this. Set (key, value), this.get (key), attribute [ Name "]. Value, ..

I am misunderstood how it works, but after some time searching and trying things I am unaware.

< / Div>

  Var obj = {name: "John", age: 23}; Up.call (obj); Work () {console.log (this); // Return {name: "John", Age: 23} console.log (this.name); // Return "John" this.wife = "Jenny"; // works console.log (this); }  

Comments