I have a class like this:
class User {
constructor(uname, pword) {
if (!uname || !pword)
throw new Error("Insufficient parameters");
if (typeof(uname) != "string" || typeof(pword) != "string") {
this.username = "";
this.password = "";
logTo("error", "Bad parameter type.", thisFile);
throw new Error("Bad parameter type.");
} else {
this.username = uname;
this.password = pword;
/* Validates the username and password format. */
if (!this.validate()) {
delete this; // Doesn't fullly delete, but removes reference- helps garbage collector to remove it.
logTo("error", "Wrong username/password format when creating user.", thisFile);
throw new Error("Wrong username/password format when creating user.");
}
}
}
}
And I was wondering whether it's possible to only instantiate this class from a named function... The reason I ask is because I'm looking to make the permissions granular, aiming for higher security.
I tried to use arguments.caller.name
, but I get an error message as so:
TypeError: 'caller', 'callee', and 'arguments' properties may not be accessed on strict mode functions or the arguments objects for calls to them.