Created
August 4, 2024 23:20
-
-
Save meowabyte/cce21f7837d4b5f302dfffc386e9c220 to your computer and use it in GitHub Desktop.
Simple monkey patch of Function.bind prototype for context searching by properties. Returns to default prototype after hit
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Callback | |
const foundContext = (ctx) => { | |
console.log(ctx) | |
} | |
// Look for context by these keys | |
const searchBy = [ | |
"chat", | |
"generateImage" | |
] | |
const bindPrototype = Function.prototype.bind | |
Function.prototype.bind = function (ctx) { | |
if(ctx && searchBy.every(k => ctx[k])) { | |
foundContext(ctx) | |
Function.prototype.bind = bindPrototype | |
} | |
return bindPrototype.apply(this, arguments) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment