Having trouble trying to declare a variable within a var namespace ..
jsFiddle .. http://jsfiddle.net/bobbyrne01/jeh7Y/
Error: SyntaxError: missing : after property id
Line: 23, Column: 8
Source Code:
var startTime = null;
var Utils = {
var startTime = null;
getStartTime: function(){
return startTime;
},
setStartTime: function(startTimeTemp){
startTime = startTimeTemp;
},
}
Utils.setStartTime(new Date());
alert(Utils.getStartTime());
You are trying declare a variable in an object literal. That is not allowed.
Instead use this idiom:
If javascript is not your first language it may be difficult to understand that startTime ‘stays’ with the instance of Utils. This is because javascript has closure. This may be worth a read.