3 ms·
I use the pattern listed under "Objects private and public members" frequently and feel they missed an important point. They really should add something like:
by IanDrake 15y ago
I use the pattern listed under "Objects private and public members" frequently and feel they missed an important point.
They really should add something like:
function MyConstructor( pub, priv ) {
var thisMyConstructor = this; //**Copy the 'this' variable**
var privateVariable = priv;
this.publicVariable = pub;
Otherwise "public" variables can't be accessed in private functions because "this" no longer references the object. So, from what I've learned it's always best to copy "this" to a private variable and use the private variable for consistency.