为什么有一个 HTMLAudioElement 和一个单独的音频 class?
Why is there an HTMLAudioElement and a seperate Audio class?
两者有什么区别?
根据 mdn,我通过以下方式创建了一个新的 HTMLAudioElement:
var audio = new Audio();
这与我通过调用 document.createElement('audio')
获得的对象有何不同?
其中一个比另一个更能证明未来吗?在哪些情况下我应该选择一个而不是另一个?
According to the spec (and the MDN article you linked to) the new Audio()
constructor simply creates an HTMLAudioElement
. Document.createElement creates an HTMLxElement
, so they are equivalent. Browsers implement the full spec so they aren't concerned.
new Audio()
的优势在于可以说更具声明性(您不一定关心它与 DOM 的关系)。另一方面,没有 new Video()
,因此为了保持一致性,您可能会发现使用 createElement
.
会有所帮助
两者有什么区别?
根据 mdn,我通过以下方式创建了一个新的 HTMLAudioElement:
var audio = new Audio();
这与我通过调用 document.createElement('audio')
获得的对象有何不同?
其中一个比另一个更能证明未来吗?在哪些情况下我应该选择一个而不是另一个?
According to the spec (and the MDN article you linked to) the new Audio()
constructor simply creates an HTMLAudioElement
. Document.createElement creates an HTMLxElement
, so they are equivalent. Browsers implement the full spec so they aren't concerned.
new Audio()
的优势在于可以说更具声明性(您不一定关心它与 DOM 的关系)。另一方面,没有 new Video()
,因此为了保持一致性,您可能会发现使用 createElement
.