Skip to content

Instantly share code, notes, and snippets.

View smaje99's full-sized avatar
🏠
Working from home

Sergio Andrés Majé Franco smaje99

🏠
Working from home
View GitHub Profile
@smaje99
smaje99 / main.js
Last active March 14, 2022 13:52
Callable Object Literal
/**
* It creates a function that has the same properties as the class it is called on.
* @see {@link 'https://docs.python.org/3/reference/datamodel.html#object.__call__'}
* @param cls - The object to be called.
* @returns A function that is callable.
*/
function ObjectCallable(cls) {
let func = () => func.__call__(this, arguments);
for (let key in cls) func[key] = cls[key];