Determine if a JavaScript function is a bound function

前端 未结 7 1558
梦如初夏
梦如初夏 2020-12-14 16:51

Is there a way to determine if a JavaScript function is a bound function?

Example:

7条回答
  •  一生所求
    2020-12-14 17:06

    I'm new here and don't have enough reputation to post comments, just answers. Sorry, but this does not answer the OP, because I have no clue how to do so. I wish I did.

    However, the very common answers relying on a missing prototype property won't work. Class methods, method definitions in objects, and async functions also don't have prototype properties, but they are not naturally bound.

    Also, bear in mind that it's still possible to manually bind a function by closure, which would defy any attempts to detect its bound state:

    const bind=(fn,obj)=>{
        return (...args)=>{
            return fn.apply(obj,args)
        }
    }
    

提交回复
热议问题