0
JAVASCRIPT PROTOTYPE
I have seen people using prototypes in factory functions. And that seems really weird infact constructor functions and its prototypes look easier, but i was wondering should i avoid factory function and use constructor function prototype?(obj.prototype.prop/meth)...coz i was wondering which one will I use in job mostly?...thank you
6 Respostas
+ 2
https://www.sololearn.com/learn/JavaScript/2979/
Yes class is ES6 way (new way)
you can use super() if you are extending class.
If you are not extending class, just define the methods inside the class definition
For
function_name.prototype.method =...
It is old way. Better compatibility. (means if the user is using old version browsers, they can still run this correctly)
+ 1
That's pre ES6 syntax and ES6 syntax
Class constructor is ES6 syntax.
Using prototype reserved word to declare prototypical function is pre ES6 way.
Pre ES6 has better browser compatibility at user side.
On the other hand, we use the improved syntax for new ECMA features when possible to reduce bugs and future proof our code.
One more point to note, these browser incompatibilities don't apply to NodeJS applications.
+ 1
For backward compatibility, use Babel library of JS, then you can use ES6 syntax without worry that some visitors cannot run the Javascript correctly and view your intended effects :
https://www.sololearn.com/Discuss/1220172/?ref=app
0
thnx bro but i am still bit confused u mean i should use the class constructor method? i mean using the consturctor and extend with super?
0
If you like to learn from tutorial, this is one:
https://www.sololearn.com/post/38381/?ref=app
0
thnx alot bro ur tha best