Last active
August 29, 2015 14:07
-
-
Save enijar/f12c343b4582f1d4b369 to your computer and use it in GitHub Desktop.
Object-Oriented JavaScript
This file contains hidden or 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
/** | |
* Cross-browser supported OOP JS class with methods | |
*/ | |
// Create a class "Config". The self-invoking | |
// function avoids the pollution the global namespace | |
var Config = (function() { | |
// Construct | |
function Config() {} | |
// Add a method "update" (that's what the prototype is for!) | |
Config.prototype.update = function(obj) { | |
this.settings = obj; | |
}; | |
// Return only the function, every other local variable stays | |
// in this scope | |
return Config; | |
})(); | |
// Instantiate class | |
var config = new Config(); | |
// Class a method "update" | |
config.update({ | |
debug: false, | |
windowWidth: $(window).width(), | |
windowHeight: $(window).height() | |
}); | |
console.log(config.settings); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment