Skip to content

Instantly share code, notes, and snippets.

@gnarl
Created July 29, 2011 20:15
Show Gist options
  • Save gnarl/1114630 to your computer and use it in GitHub Desktop.
Save gnarl/1114630 to your computer and use it in GitHub Desktop.
JavaScript Prototypes
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