Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
这可以在 JavaScript 中完成吗?
type == 1 ? function1() : function2();
是的,这是有效的代码。它将调用或 function1() , function2()但不会同时调用 - 取决于 的值type。
function1()
function2()
type
它不会调用两个函数。它将调用您的两个函数之一。