I have code like this: (and on jsfiddle http://jsfiddle.net/k6zNm/3/)
(function(){
Marker = function(opts){
var marker = this;
marker.Version = "2012.Jul.06";
marker.HelloWorld = function(){
return marker.Version;
}
}
})();
window.mymarker = new Marker();
$("div#message").text(mymarker.HelloWorld());
The code works fine. But I think the (function(){})(); is a closure. Why can I access the Marker in it. Isn’t it a pollution to global namespace?
You haven’t used
varwithMarker, so it is a global variable instead of being scoped to the function.