2
I am in need of a help in the use of Prototypes, I want to organize and maintain a cleaner code and can reuse my classes at other times... And in the research the use of Prototype seems to be something advantageous... (I may have got it wrong, correct me...)
First I’ll put my code down and then my doubts...
var Model = function(hello) {
this.hello = hello;
//meu teste
this._init();
}
Model.prototype = function(){
var _init = function(){
console.log("Init...");
this.helloWorld();
},
_helloWorld = function(){
alert(this.hello)
};
return {
helloWorld : _helloWorld
};
}();
1° Doubt: Inside my Builder how could I call my function "_init"? Since it’s private, I’d like you to take the first call inside the builder.. In my example above, I made the call via "this. _init()", but had the error:
Uncaught TypeError: this._init is not a function
2° Doubt: Within my "_init" function will I, and will I have calls from other methods, in this example: "_helloWorld", would the way I did work? Or what the right way?
Valeu Pessoal.
Interesting fact: why not use the JS class in this case?
– Woss
@Andersoncarloswoss has an example? As I commented, at first the way to structure code so pleased me... But, I’m open to new tips!
– Roni Sommerfeld