Monday, 15 August 2011

Javascript Module Pattern / Prototype Pattern : can't figure out this code -



Javascript Module Pattern / Prototype Pattern : can't figure out this code -

i trying create simple google maps plugin. i'm next tutorial can't figure out block of code. explain me code ?

(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 } }; homecoming mapster; }()); mapster.create = function(element, opts) { homecoming new mapster(element, opts); }; window.mapster = mapster; }(window, google));

// 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 } }; homecoming mapster; }()); // convenience function create new instances of `mapster` mapster.create = function (element, opts) { homecoming new mapster(element, opts); }; // exposing `mapster` globally window.mapster = mapster; // passing in `window` & `google` params iife }(window, google)); // usage: var mapster = mapster.create(someel, {}); console.log(mapster.gmap);

hopefully comments clear up!

javascript design-patterns module prototype

No comments:

Post a Comment