Skip to content

Instantly share code, notes, and snippets.

@meowabyte
Last active July 24, 2025 23:12
Show Gist options
  • Save meowabyte/cce21f7837d4b5f302dfffc386e9c220 to your computer and use it in GitHub Desktop.
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
// Callback
const foundContext = (ctx) => {
console.log(ctx)
}
// Look for context by these keys
const searchBy = [
"chat",
"generateImage"
]
Function.prototype.bind = (() => {
const o = Function.prototype.bind
return function (ctx) {
if(typeof ctx !== "undefined" && searchBy.every(k => k in ctx)) {
Function.prototype.bind = o
foundContext(ctx)
}
return bindPrototype.apply(this, arguments)
}
})()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment