如何在没有括号的情况下调用函数时传递参数[Javascript]

编程入门 行业动态 更新时间:2024-10-28 06:25:07
本文介绍了如何在没有括号的情况下调用函数时传递参数[Javascript]的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我有一个名为tryMe的函数,我在没有括号的情况下调用它并不是这样,但这个想法就像你在这里做的那样:

I have a function called "tryMe" and I'm calling it without the parenthesis not precisely this but the idea is like what you would do here:

setTimeout(tryMe,200);

如何传递我需要的参数?

how can I pass parameters that I need?

我正在使用一个jquery插件,它允许我调用一个函数,但我必须用括号调用它,或者它在加载时自行执行。

I am using a jquery plugin that enables me to call a function but I have to call it withou the parenthesis or it executes itself upon loading.

推荐答案

setTimeout(function() { tryMe(parm1, parm2); }, 200);

更强大的产品,确保 parm1的值, parm2 在超时发生之前不要更改(@ lincolnk的评论):

A more robust offering, to ensure that the values of parm1, parm2 don't change before the timeout fires (per @lincolnk's comment):

setTimeout(function() { var p1 = parm1; var p2 = parm2; tryMe(p1, p2); }, 200);

@patrick dw,你是对的,必须先评价。

@patrick dw, you're right, has to be evaluated before.

更多推荐

如何在没有括号的情况下调用函数时传递参数[Javascript]

本文发布于:2023-07-22 13:33:49,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1187956.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:括号   函数   情况下   参数   如何在

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!