JavaScript how to create inner function with function as an argument without imidietly invoking it? [duplicate]










0
















This question already has an answer here:



  • JavaScript: Passing parameters to a callback function

    11 answers



I tried this but it's immediately invokes addClass after opening website :



function onMouseOver(element, event) 
element.addEventListener("mouseover", () =>
event
)


onMouseOver(startAnim, addClass(panelLeft, 'hidden-l'));
onMouseOver(startAnim, addClass(panelRight, 'hidden-r'));









share|improve this question















marked as duplicate by Rajesh javascript
Users with the  javascript badge can single-handedly close javascript questions as duplicates and reopen them as needed.

StackExchange.ready(function()
if (StackExchange.options.isMobile) return;

$('.dupe-hammer-message-hover:not(.hover-bound)').each(function()
var $hover = $(this).addClass('hover-bound'),
$msg = $hover.siblings('.dupe-hammer-message');

$hover.hover(
function()
$hover.showInfoMessage('',
messageElement: $msg.clone().show(),
transient: false,
position: my: 'bottom left', at: 'top center', offsetTop: -7 ,
dismissable: false,
relativeToBody: true
);
,
function()
StackExchange.helpers.removeMessages();

);
);
);
Nov 15 '18 at 5:56


This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.


















  • Adding parenthesis after function will make it run immediately. You can try addClass.bind(null, panelLeft, 'hidden-l'). This will bind context and arguments and return a reference instead.

    – Rajesh
    Nov 15 '18 at 5:53
















0
















This question already has an answer here:



  • JavaScript: Passing parameters to a callback function

    11 answers



I tried this but it's immediately invokes addClass after opening website :



function onMouseOver(element, event) 
element.addEventListener("mouseover", () =>
event
)


onMouseOver(startAnim, addClass(panelLeft, 'hidden-l'));
onMouseOver(startAnim, addClass(panelRight, 'hidden-r'));









share|improve this question















marked as duplicate by Rajesh javascript
Users with the  javascript badge can single-handedly close javascript questions as duplicates and reopen them as needed.

StackExchange.ready(function()
if (StackExchange.options.isMobile) return;

$('.dupe-hammer-message-hover:not(.hover-bound)').each(function()
var $hover = $(this).addClass('hover-bound'),
$msg = $hover.siblings('.dupe-hammer-message');

$hover.hover(
function()
$hover.showInfoMessage('',
messageElement: $msg.clone().show(),
transient: false,
position: my: 'bottom left', at: 'top center', offsetTop: -7 ,
dismissable: false,
relativeToBody: true
);
,
function()
StackExchange.helpers.removeMessages();

);
);
);
Nov 15 '18 at 5:56


This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.


















  • Adding parenthesis after function will make it run immediately. You can try addClass.bind(null, panelLeft, 'hidden-l'). This will bind context and arguments and return a reference instead.

    – Rajesh
    Nov 15 '18 at 5:53














0












0








0









This question already has an answer here:



  • JavaScript: Passing parameters to a callback function

    11 answers



I tried this but it's immediately invokes addClass after opening website :



function onMouseOver(element, event) 
element.addEventListener("mouseover", () =>
event
)


onMouseOver(startAnim, addClass(panelLeft, 'hidden-l'));
onMouseOver(startAnim, addClass(panelRight, 'hidden-r'));









share|improve this question

















This question already has an answer here:



  • JavaScript: Passing parameters to a callback function

    11 answers



I tried this but it's immediately invokes addClass after opening website :



function onMouseOver(element, event) 
element.addEventListener("mouseover", () =>
event
)


onMouseOver(startAnim, addClass(panelLeft, 'hidden-l'));
onMouseOver(startAnim, addClass(panelRight, 'hidden-r'));




This question already has an answer here:



  • JavaScript: Passing parameters to a callback function

    11 answers







javascript function






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Nov 15 '18 at 5:52









Rajesh

16.6k52254




16.6k52254










asked Nov 15 '18 at 5:50









MarcinMarcin

32




32




marked as duplicate by Rajesh javascript
Users with the  javascript badge can single-handedly close javascript questions as duplicates and reopen them as needed.

StackExchange.ready(function()
if (StackExchange.options.isMobile) return;

$('.dupe-hammer-message-hover:not(.hover-bound)').each(function()
var $hover = $(this).addClass('hover-bound'),
$msg = $hover.siblings('.dupe-hammer-message');

$hover.hover(
function()
$hover.showInfoMessage('',
messageElement: $msg.clone().show(),
transient: false,
position: my: 'bottom left', at: 'top center', offsetTop: -7 ,
dismissable: false,
relativeToBody: true
);
,
function()
StackExchange.helpers.removeMessages();

);
);
);
Nov 15 '18 at 5:56


This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.









marked as duplicate by Rajesh javascript
Users with the  javascript badge can single-handedly close javascript questions as duplicates and reopen them as needed.

StackExchange.ready(function()
if (StackExchange.options.isMobile) return;

$('.dupe-hammer-message-hover:not(.hover-bound)').each(function()
var $hover = $(this).addClass('hover-bound'),
$msg = $hover.siblings('.dupe-hammer-message');

$hover.hover(
function()
$hover.showInfoMessage('',
messageElement: $msg.clone().show(),
transient: false,
position: my: 'bottom left', at: 'top center', offsetTop: -7 ,
dismissable: false,
relativeToBody: true
);
,
function()
StackExchange.helpers.removeMessages();

);
);
);
Nov 15 '18 at 5:56


This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.














  • Adding parenthesis after function will make it run immediately. You can try addClass.bind(null, panelLeft, 'hidden-l'). This will bind context and arguments and return a reference instead.

    – Rajesh
    Nov 15 '18 at 5:53


















  • Adding parenthesis after function will make it run immediately. You can try addClass.bind(null, panelLeft, 'hidden-l'). This will bind context and arguments and return a reference instead.

    – Rajesh
    Nov 15 '18 at 5:53

















Adding parenthesis after function will make it run immediately. You can try addClass.bind(null, panelLeft, 'hidden-l'). This will bind context and arguments and return a reference instead.

– Rajesh
Nov 15 '18 at 5:53






Adding parenthesis after function will make it run immediately. You can try addClass.bind(null, panelLeft, 'hidden-l'). This will bind context and arguments and return a reference instead.

– Rajesh
Nov 15 '18 at 5:53













1 Answer
1






active

oldest

votes


















0














"bind" is what you are looking for and below you can see reference of how to use it.






function innerFn(a, b) 
console.log('Inner fn called with params ',a ,b)


function outerFn(c, fn)
console.log('Outer fn called with params ',c)

fn()


outerFn('1', innerFn.bind(null, '2', '3'))








share|improve this answer























  • Most of the topics are answered. We should look for similar post as we know the real issue and can formulate better search query. Once we have such post, we should share its link in comments section until you have privilege to close yourself

    – Rajesh
    Nov 15 '18 at 5:58











  • Sure @Rajesh. Will take care of this. :)

    – Nitish Narang
    Nov 15 '18 at 5:59

















1 Answer
1






active

oldest

votes








1 Answer
1






active

oldest

votes









active

oldest

votes






active

oldest

votes









0














"bind" is what you are looking for and below you can see reference of how to use it.






function innerFn(a, b) 
console.log('Inner fn called with params ',a ,b)


function outerFn(c, fn)
console.log('Outer fn called with params ',c)

fn()


outerFn('1', innerFn.bind(null, '2', '3'))








share|improve this answer























  • Most of the topics are answered. We should look for similar post as we know the real issue and can formulate better search query. Once we have such post, we should share its link in comments section until you have privilege to close yourself

    – Rajesh
    Nov 15 '18 at 5:58











  • Sure @Rajesh. Will take care of this. :)

    – Nitish Narang
    Nov 15 '18 at 5:59















0














"bind" is what you are looking for and below you can see reference of how to use it.






function innerFn(a, b) 
console.log('Inner fn called with params ',a ,b)


function outerFn(c, fn)
console.log('Outer fn called with params ',c)

fn()


outerFn('1', innerFn.bind(null, '2', '3'))








share|improve this answer























  • Most of the topics are answered. We should look for similar post as we know the real issue and can formulate better search query. Once we have such post, we should share its link in comments section until you have privilege to close yourself

    – Rajesh
    Nov 15 '18 at 5:58











  • Sure @Rajesh. Will take care of this. :)

    – Nitish Narang
    Nov 15 '18 at 5:59













0












0








0







"bind" is what you are looking for and below you can see reference of how to use it.






function innerFn(a, b) 
console.log('Inner fn called with params ',a ,b)


function outerFn(c, fn)
console.log('Outer fn called with params ',c)

fn()


outerFn('1', innerFn.bind(null, '2', '3'))








share|improve this answer













"bind" is what you are looking for and below you can see reference of how to use it.






function innerFn(a, b) 
console.log('Inner fn called with params ',a ,b)


function outerFn(c, fn)
console.log('Outer fn called with params ',c)

fn()


outerFn('1', innerFn.bind(null, '2', '3'))








function innerFn(a, b) 
console.log('Inner fn called with params ',a ,b)


function outerFn(c, fn)
console.log('Outer fn called with params ',c)

fn()


outerFn('1', innerFn.bind(null, '2', '3'))





function innerFn(a, b) 
console.log('Inner fn called with params ',a ,b)


function outerFn(c, fn)
console.log('Outer fn called with params ',c)

fn()


outerFn('1', innerFn.bind(null, '2', '3'))






share|improve this answer












share|improve this answer



share|improve this answer










answered Nov 15 '18 at 5:54









Nitish NarangNitish Narang

2,9701815




2,9701815












  • Most of the topics are answered. We should look for similar post as we know the real issue and can formulate better search query. Once we have such post, we should share its link in comments section until you have privilege to close yourself

    – Rajesh
    Nov 15 '18 at 5:58











  • Sure @Rajesh. Will take care of this. :)

    – Nitish Narang
    Nov 15 '18 at 5:59

















  • Most of the topics are answered. We should look for similar post as we know the real issue and can formulate better search query. Once we have such post, we should share its link in comments section until you have privilege to close yourself

    – Rajesh
    Nov 15 '18 at 5:58











  • Sure @Rajesh. Will take care of this. :)

    – Nitish Narang
    Nov 15 '18 at 5:59
















Most of the topics are answered. We should look for similar post as we know the real issue and can formulate better search query. Once we have such post, we should share its link in comments section until you have privilege to close yourself

– Rajesh
Nov 15 '18 at 5:58





Most of the topics are answered. We should look for similar post as we know the real issue and can formulate better search query. Once we have such post, we should share its link in comments section until you have privilege to close yourself

– Rajesh
Nov 15 '18 at 5:58













Sure @Rajesh. Will take care of this. :)

– Nitish Narang
Nov 15 '18 at 5:59





Sure @Rajesh. Will take care of this. :)

– Nitish Narang
Nov 15 '18 at 5:59





Popular posts from this blog

Use pre created SQLite database for Android project in kotlin

Darth Vader #20

Ondo