Component.jsChe cos'è questo modello chiamato Javascript? ha un nome?
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);
}
};
})();
poi in html
<script src="component.js"></script>
<script>
// init the component
component.init({
array_option : [1,2,3],
});
</script>
Il motivo che mi chiedo è che ho visto con l'esempio e ho pensato che aveva un senso, ma è il loro qualsiasi lettura sul perché questo è un bene pratica? è questo Javascript orientato agli oggetti?
se questo IS OO javascript, questo schema rende inutili le definizioni di prototipo?
Buona risposta alla domanda di cui sopra
Javascript: Module Pattern vs Constructor/Prototype pattern?
Così tante risposte, tutte diverse ... – Blindy