Created
July 29, 2011 20:15
-
-
Save gnarl/1114630 to your computer and use it in GitHub Desktop.
JavaScript Prototypes
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var man = (function() { | |
var m_that = {}; | |
var photo_prototype = function(spec, my) { | |
var that = {}; | |
var my = my || {}; | |
that.obj_name = "photo_proto"; | |
var get_name = function () { | |
alert("Called get_name"); | |
return that.obj_name; | |
}; | |
that.get_name = get_name; | |
return that; | |
}; | |
//photo_debug_prototype | |
var photo_debug_prototype = function(spec, my) { | |
var that = photo_prototype(spec, my); | |
var my = my || {}; | |
that.obj_name = "photo_debug_prototype"; | |
var capturePhoto = function() { | |
alert("debug: capturePhoto - need to add return statement here."); | |
}; | |
that.capturePhoto = capturePhoto; | |
return that; | |
}; | |
//photo | |
var photo = function(spec, my) { | |
var debug_mode = spec.debug || false; | |
var my = my || {}; | |
if (debug_mode) { | |
var that = photo_debug_prototype(spec, my); | |
} | |
else { | |
var that = photo_prototype(spec, my); | |
} | |
return that; | |
}; | |
m_that.photo = photo; | |
return m_that; | |
})(); | |
var onBodyLoad = function() { | |
var m = man; | |
var my_photo = m.photo({}, {}); | |
alert("photo_prototype: name = " + my_photo.get_name()); | |
var my_photo_debug = m.photo({debug: true}); | |
alert("photo_debug_prototype: name = " + my_photo_debug.get_name()); | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment