具有供應商前綴的 API

在網頁上,新的 API 在實驗階段通常會有供應商前綴。例如,在撰寫本文時,AudioContext API 在 Safari 中稱為 webkitAudioContextvendor_prefix 屬性表示這些替代名稱,如果未定義正常名稱,則會使用這些名稱。

例如,要使用 AudioContext,您可以執行


# #![allow(unused_variables)]
#fn main() {
#[wasm_bindgen]
extern "C" {
    #[wasm_bindgen(vendor_prefix = webkit)]
    type AudioContext;

    // methods on `AudioContext` ...
}
#}

每當使用 AudioContext 時,如果全域命名空間定義了 AudioContext,它就會使用 AudioContext,否則會回退到 webkitAudioContext

請注意,vendor_prefix 無法與 module = "..."js_namespace = ... 一起使用,因此基本上僅限於今天的網路平台 API。