简体   繁体   English

如何扩展AudioNode(没有构造函数的本地对象)

[英]How to extend AudioNode (native object without constructor)

I'm trying to put this code to use (a tone.js piano, not written by me). 我正在尝试使用此代码 (tone.js钢琴,不是我写的)。

The piano class extends AudioNode like so: 钢琴课扩展了AudioNode,如下所示:

class Piano extends AudioNode {

    constructor(){

        super()
        // piano specific stuff...
    }
}

When I try to instantiate it, following the documentation, with 当我尝试实例化它时,遵循文档,

const piano = new Piano()

I get "TypeError: Illegal constructor". 我收到“ TypeError:非法构造函数”。

What is then the correct way to extend a native object such as AudioNode that can't be instantiated with new ? 那么扩展无法用new实例化的本机对象(如AudioNode)的正确方法是什么? Did something change in the recent past so that the above code no longer works? 最近发生了什么变化,因此上述代码不再起作用?

The AudioNode in the example you are referring to is taken from the tone.js library. AudioNode在你指的是从tone.js库中提取的例子。 Take a look at the import statement: 看一下import语句:

import Tone, { Gain, Frequency, AudioNode, Buffer} from 'tone'

The error you get is a sign that you did not import the AudioNode from the library. 您收到的错误表明您没有从库中导入AudioNode That's why your code is using the native AudioNode type that cannot be extended. 这就是为什么您的代码使用无法扩展的本机AudioNode类型的原因。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM