03-16-2016, 11:39 AM
JavaScript prototype?
Currently, any object I create does this:
Would there be any significant performance improvements to instead use
?
I originally avoided this because finding clear and concise JavaScript ref. sometimes is well, impossible. Thus, any example of prototype I'd ever seen was ... confusing. Well, last night, while working on my new hacking project, I observed that all object methods are defined using prototype. If there's a significant enough improvement to performance, I don't mind going through some of my code and changing it to use prototype. (aside from the INI parser, since that makes Flash ActionScript porting... not as easy, and it was designed so a port to AS2 would be ... "smooth". Also it's a small library that doesn't do intensive stuff, anyways) However, if it's not very significant, I'd rather not bother.
Currently, my html5 game doesn't perform super well for me when it has a lot of entities on the screen. If I can improve it without writing a lot of very confusing code I wouldn't understand (like an __extends function...) , I will. I fear that as it stands, it's not going to meet any of my requirements for even developing the library/engine/<WHATEVER THE HELL YOU WANNA CALL IT> behind it.
Currently, any object I create does this:
Code:
function Object0(pars...) {
this.prop = value;
this.method = function(pars...) {
//code
}
}
Would there be any significant performance improvements to instead use
Code:
function Object0(pars...) {
this.prop = value;
}
Object0.prototype.method = function(pars...) {
//code
}
I originally avoided this because finding clear and concise JavaScript ref. sometimes is well, impossible. Thus, any example of prototype I'd ever seen was ... confusing. Well, last night, while working on my new hacking project, I observed that all object methods are defined using prototype. If there's a significant enough improvement to performance, I don't mind going through some of my code and changing it to use prototype. (aside from the INI parser, since that makes Flash ActionScript porting... not as easy, and it was designed so a port to AS2 would be ... "smooth". Also it's a small library that doesn't do intensive stuff, anyways) However, if it's not very significant, I'd rather not bother.
Currently, my html5 game doesn't perform super well for me when it has a lot of entities on the screen. If I can improve it without writing a lot of very confusing code I wouldn't understand (like an __extends function...) , I will. I fear that as it stands, it's not going to meet any of my requirements for even developing the library/engine/<WHATEVER THE HELL YOU WANNA CALL IT> behind it.