Call function with “this”

后端 未结 2 2037
别跟我提以往
别跟我提以往 2020-12-16 01:37
2条回答
  •  离开以前
    2020-12-16 02:15

    The following ought to do it:

    function handleOnClick() {
        if( confirm( "Sure?" ) ) {
            return handleOnClickConfirmed.call( this );
        }
        return false;
    }
    

    The call() function attached to Function objects is designed to allow this; calling a function with a desired context. It's an extremely useful trick when setting up event handlers that call back into functions within other objects.

提交回复
热议问题