我试图创建一个简单的谷歌地图插件。我正在学习一个教程,但我无法理解这段代码。有人能解释我的密码吗?
(function(window, google) {
var Mapster = (function() {
function Mapster(element, opts) {
this.gMap = new google.maps.Map(element,opts);
}
Mapster.prototype = {
zoom: function(level) {
//some code here
}
};
return Mapster;
}());
Mapster.create = function(element, opts) {
return new Mapster(element, opts);
};
window.Mapster = Mapster;
}(window, google));发布于 2014-10-13 09:56:44
// http://benalman.com/news/2010/11/immediately-invoked-function-expression/
(function (window, google) {
// local `Mapster` IIFE
var Mapster = (function () {
// local `Mapster` constructor function
function Mapster(element, opts) {
this.gMap = new google.maps.Map(element, opts);
}
Mapster.prototype = {
zoom: function (level) {
//some code here
}
};
return Mapster;
}());
// convenience function to create new instances of `Mapster`
Mapster.create = function (element, opts) {
return new Mapster(element, opts);
};
// exposing `Mapster` globally
window.Mapster = Mapster;
// passing in `window` & `google` as params to the IIFE
}(window, google));
// usage:
var mapster = Mapster.create(someEl, {});
console.log(mapster.gMap);希望这些评论能澄清这一点!
https://stackoverflow.com/questions/26336952
复制相似问题