javascript - Calling a function which is inside of a function -
my c# oriented braincells keep telling me should work:
var myapp = function() { currenttime = function() { return new date(); }; }; myapp.currenttime(); clearly doesn't. if javascript function object, shouldn't able call function on object? missing?
currenttime global (set when call myapp), not property of myapp.
to call it, without redefining function:
myapp(); currenttime(); however, sounds want either:
a simple object
var myapp = { currenttime: function() { return new date(); }; }; myapp.currenttime(); a constructor function
var myapp = function() { this.currenttime = function() { return new date(); }; }; var myappinstance = new myapp(); myappinstance.currenttime();
Comments
Post a Comment