Consider the following JS object, it has:
- x: a variable given value 100
- p: prints value of x, called immediately after creation
- y: prints value of x, called after object creation
When the value of Pipe.x is printed immediately during Object creation, for some reason Pipe.x is undefined but when P.y() is called, after an object, the Object has been created, the Value of Pipe.x is 100, as it should have been in the first place.
var Pipe = {
x: 100,
p: function(){
console.log('p says x is ' + this.x); // prints y says x is undefined
}(), // call immediately
y: function(){
console.log('y says x is ' + this.x);
}
}
Pipe.y(); // prints y says x is 100
Is there any JS object property I'm missing which makes Pipe.p() print undefined and P.y() print 100?