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

Popular posts from this blog

python - Subclassed QStyledItemDelegate ignores Stylesheet -

java - HttpClient 3.1 Connection pooling vs HttpClient 4.3.2 -

SQL: Divide the sum of values in one table with the count of rows in another -