Skip to content

Instantly share code, notes, and snippets.

@leviathan
Forked from anonymous/demo.js
Created March 31, 2011 14:28
Show Gist options
  • Save leviathan/896438 to your computer and use it in GitHub Desktop.
Save leviathan/896438 to your computer and use it in GitHub Desktop.
// Initialize namespaces ---------------------
if (!window.mm) {
mm = {};
}
// avoid window. use this if you "think" you are in root closure. makes encapsulation possible and code executable without DOM (like node...)
if (!this.mm) {
mm = {};
}
// or (freaky) don't try to understand! ;)
mm = this.mm || {};
// Writing constructors or general functions in namespace:
// Instead:
function MapEditor(mapContainerId) {
// private properties
var i18n = null;
var googleMapOptions = {
...
// do:
mm.MapEditor = function(mapContainerId) {
...
instance = new mm.MapEditor(...)
// var xy; is only local to current function call, but all called functions get it too!
// From the JS Godfather: http://www.crockford.com/javascript/private.html
// How to make a Polyline editable with draggable edges
function ExtPolyline() {
// delegate instead of subclasses, because subclasses of google's polyline don't work too well
var googlePolyline = new google.maps.Polyline();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment