My target:
I would like to create a function that does not inherit methods from Function.prototype by default, or at least hide them in a TypeScript environment. By ‘hide them’, I mean that when I access the function using dot notation, I do not want to see the default methods like apply, bind, call.
To understand my intention better, please read the following code:
let logValue: any
type callableLoggerType = (side: string, args: any) => void
interface loggerType {
setHandle(): void
}
const makeLoggerCallable: callableLoggerType = (side: string, args: any): void => {
if ((side === null || undefined) && (args === null || undefined)) Error("something wrong on logger pattern.")
if (side === "web") logValue = args
if (side === "nod") logValue = args
}
class LoggerLogic implements loggerType {
public setHandle(): void {
console.log(`nnlogger handler is configurednn`)
logValue === null || undefined ? new Error("Error in logger arguments") : console.log(logValue)
}
}
const loggerInstance = new LoggerLogic()
Object.setPrototypeOf(makeLoggerCallable, loggerInstance)
const logger = Object.assign(makeLoggerCallable, loggerInstance)
NOTE:
i know in some lines it should be unknown
instead any
, but i really want it to be any
in my case.
The real problem:
So, the real issue that I want to avoid, even if it does not cause any harm to the logic or the code itself, is when I try to access the class methods I created using dot notation in logger. When I do this, the default methods apply, call, bind, etc., appear.”
// when i type the dot, the function.prototype appear
logger.
// then any developer user can use it or at least type it
logger.apply()
logger.bind()
logger.call()
i have no idea to hide it in typescript env, and i would to hide it from developer users