JavaScript how to create inner function with function as an argument without imidietly invoking it? [duplicate]
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'));
javascript function
marked as duplicate by Rajesh
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.
add a comment |
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'));
javascript function
marked as duplicate by Rajesh
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 tryaddClass.bind(null, panelLeft, 'hidden-l')
. This will bind context and arguments and return a reference instead.
– Rajesh
Nov 15 '18 at 5:53
add a comment |
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'));
javascript function
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
javascript function
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
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
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 tryaddClass.bind(null, panelLeft, 'hidden-l')
. This will bind context and arguments and return a reference instead.
– Rajesh
Nov 15 '18 at 5:53
add a comment |
Adding parenthesis after function will make it run immediately. You can tryaddClass.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
add a comment |
1 Answer
1
active
oldest
votes
"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'))
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
add a comment |
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
"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'))
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
add a comment |
"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'))
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
add a comment |
"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'))
"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'))
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
add a comment |
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
add a comment |
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