我想把一個if語句放在一個對象中,但我不確定它是否可能。如何滿足某些條件時創建只有值的對象?
這是我的目標。
function typed(){
$(".code-animate").typed({
strings: options.typed.strings,
typeSpeed: options.typed.typeSpeed,
backSpeed: options.typed.backSpeed,
contentType: 'text',
loop: true,
if(options.typed.callback)callback: options.typed.callback // this is what I am trying to do
});
}
謝謝你的例子,不幸的是我不能傳遞'null',因爲我無法控制'callback:'接受什麼。我只能通過它期望的值或根本沒有設置它 –
然後第三個例子是你需要的。 – Renan