最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - Devtools console: Function was resolved from bound function - Stack Overflow

programmeradmin3浏览0评论

Browsers have a window.stop() function which I have overwritten for my own purposes:

window.stop = (s,t,o,p=window) => { ... };

I'm trying to troubleshoot why calling my stop() function does not work in some contexts, such as inside a function called from an anonymous function that is itself called via setTimeout(). In one part of my project where the code malfunctions I have inserted the following:

console.log('calling console.log(stop) on the next line');
console.log(stop);

Then, I opened the browser console and typed console.log(stop) which yielded the expected output.

This is all exhibited in the following screenshot:

Note the little blue 'i' icon, which I hovered the mouse over.

What does 'Function was resolved from bound function' mean? I could not find any information anywhere about this message. How can I prevent that, such that my stop() function is called instead of the native one?

Browsers have a window.stop() function which I have overwritten for my own purposes:

window.stop = (s,t,o,p=window) => { ... };

I'm trying to troubleshoot why calling my stop() function does not work in some contexts, such as inside a function called from an anonymous function that is itself called via setTimeout(). In one part of my project where the code malfunctions I have inserted the following:

console.log('calling console.log(stop) on the next line');
console.log(stop);

Then, I opened the browser console and typed console.log(stop) which yielded the expected output.

This is all exhibited in the following screenshot:

Note the little blue 'i' icon, which I hovered the mouse over.

What does 'Function was resolved from bound function' mean? I could not find any information anywhere about this message. How can I prevent that, such that my stop() function is called instead of the native one?

Share Improve this question edited Feb 16 at 6:18 Jamesfo asked Feb 15 at 4:52 JamesfoJamesfo 5726 silver badges15 bronze badges 1
  • 1 Can you provide a minimal reproducible example? – jabaa Commented Feb 15 at 12:13
Add a comment  | 

2 Answers 2

Reset to default 0

Explicitly Store Your Function in a Different Variable

const myStop = (s, t, o, p = window) => { 
    console.log("Custom stop called");
};
window.stop = myStop;

Then, always call myStop() instead of relying on stop.

Potential Issues with Overriding window.stop():

  • Asynchronous Contexts: Functions called within setTimeout() or other asynchronous operations may explicitly reference the original window.stop() if they were bound to it before your override.

  • Third-Party Libraries: External scripts or libraries might bind window.stop() to their own contexts, leading to conflicts.

  • Browser Implementations: Some browsers might implement window.stop() in a way that doesn't allow it to be fully overridden, or they might restore the original function under certain conditions.

You would have to ensure your override preceedes any other code to avoid things like this:

setTimeout((originalStop) => {
    console.log("timed window.stop()");
    originalStop();
}, 1000, window.stop.bind(window));

window.stop = () => console.log("my overidden stop");
发布评论

评论列表(0)

  1. 暂无评论