component.js
var component = (function(){
var self;
var default_options = {
array_option : [],
string_option : "default"
};
return {
other_function: function(args) {
},
init: function(options) {
self = this;
// merge in user options
for (var attr in options) {
if (options.hasOwnProperty(attr)) {
self.o[attr] = options[attr];
}
}
/***
* Initialize component
*/
self.other_function(args);
}
};
})();
then in the html
<script src="component.js"></script>
<script>
// init the component
component.init({
array_option : [1,2,3],
});
</script>
The reason I ask is I have seen it by example and thought it made sense, but is their any reading on why this is good practice? is this Object-Oriented Javascript?
if this IS OO javascript, does this pattern make prototypal definitions useless?
Good answer to above question
Javascript: Module Pattern vs Constructor/Prototype pattern?