TimeControl = function(time){
this.time=time;
console.log('time control initialized time is ='+this.time);
}
TimeControl.prototype = {
getTime:function(){
return this.time;
}
}
Box = function(x,y,value) {
this.x = x;
this.y = y;
this.time = value;
// Create a new object of TimeControl
//this.timeControl = new TimeControl(this.time); // OK to create object here!
}
Box.prototype = {
xyz:this.time,
// Create a new object of TimeControl
timeControl:function(){return new TimeControl(this.time)}, // But not OK here! Works if I enter a number
test1: function() {
return this.time;
},
test2: function() {
return this.timeControl().getTime();
}
};
var box = new Box(10,10,14);
console.log("Duration: " + box.test1()); // Works fine
console.log("Duration: " + box.test2()); // Returns undefined
console.log("xyz: " + box.xyz);
Please Whitelist JSFiddle in your content blocker.
Help keep JSFiddle free for always by one of two ways:
Whitelist JSFiddle in your content blocker (two clicks)
Go PRO and get access to additional PRO features →
Join the 4+ million users, and keep the JSFiddle dream alive.
Ad-free
All ads in the editor and listing pages are turned completely off.
Fiddle Pages
Your fiddles accessible under a custom domain and a vanity path - the simplest hosting for your personal project.
Use pre-released features
You get to try and use features (like the Palette Color Generator) months before everyone else.
Fiddle collections
Sort and categorize your Fiddles into multiple collections.
Private collections and fiddles
You can make as many Private Fiddles, and Private Collections as you wish!
Get Fiddle Pages with PRO
Your fiddles accessible under a custom domain and a vanity path - the simplest hosting for your personal project.