2 ms·
I don't know the author's reasoning, but I read Crockford's JavaScript: The Good Parts, which demonstrates several OOP styles (including this one). One of the
by TazeTSchnitzel 15y ago
I don't know the author's reasoning, but I read Crockford's JavaScript: The Good Parts, which demonstrates several OOP styles (including this one).
One of the reasons he likely didn't use the "this" keyword is because it's compromisable. "this" is anything that the invoker of the method wants it to be, so you can accidentally compromise information.
Also, if you have your variables in function scope and the function is created in that scope, the keyword is unnecessary.
Regarding not using new/constructor functions, some people think the non-constructor-based OOP model in JS is nicer.
Finally, regarding lack of prototypes, if you want to keep secrets then you can't re-use functions. On the other hand, if you are creating public/non-privileged methods, no reason not to re-use functions.