吴小倩, W3C
2019年 11 月
吴小倩, W3C
2019年 11 月
[SecureContext, Exposed=Window]
interface PaymentRequest : EventTarget {
constructor(
sequence<PaymentMethodData> methodData,
PaymentDetailsInit details,
optional PaymentOptions options = {}
);
[NewObject]
Promise<PaymentResponse> show(optional Promise<PaymentDetailsUpdate> detailsPromise);
readonly attribute DOMString? shippingOption;
}
Web IDL 的关键在于定义了如何把 DOM 和相关的 Web API 映射到语言里,尤其是 ECMAScript。之前的标准都使用 OMG IDL,没有正式的对这些映射关系做出定义,实现者需要从字里行间猜测。
Maciej Stachowiak (Webkit), 2009-9-28
Platform objects?
Yes!
Yes!
Yes!
Yes!
Platform objects?
Yes!
Yes!
Yes!
Yes!
[Exposed=Window]
interface Student {
constructor();
attribute unsigned long id;
stringifier attribute DOMString name;
};
var s = new Student();
s.id = 12345678;
s.name = '周杰倫';
var greeting = 'Hello, ' + s + '!'; // Now greeting == 'Hello, 周杰倫!'.
[extended_attributes]
interface identifier {
/* interface_members... */
};
constructor //构造新对象,初始化为 this 或抛出异常
stringifier //关键字,非默认字符串转换
unsigned long //Type 的一种,[0, 4294967295]
DOMString //所有可能的 code units 序列的集合,不包含 null
[SecureContext, Exposed=Window]
interface PaymentRequest : EventTarget {
constructor(
sequence<PaymentMethodData> methodData,
PaymentDetailsInit details,
optional PaymentOptions options = {}
);
[NewObject]
Promise<PaymentResponse> show(optional Promise<PaymentDetailsUpdate> detailsPromise);
readonly attribute DOMString? shippingOption;
}
[NewObject] //方法的引用者总是一个对象实例
SecureContext //Secure Contexts 规范定义的安全上下文
Promise //参考 Writing Promise-Using Specifications
DOMString? // nullable DOMString
[Exposed=(Window,Worker)]
interface Performance : EventTarget {
DOMHighResTimeStamp now();
readonly attribute DOMHighResTimeStamp timeOrigin;
[Default] object toJSON();
};
partial interface mixin WindowOrWorkerGlobalScope {
[Replaceable] readonly attribute Performance performance;
};
interface mixin //多个接口可共用的方法和属性
partial interface //可在多个规范定义同一个interface
[Default] //默认行为算法必须执行
[Replaceable] //可后续指定值
Throw a TypeError //Web IDL 不可自定义 exception
欢迎提问?