Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/418.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript `构造函数中的“”上下文不清楚_Javascript_Constructor - Fatal编程技术网

Javascript `构造函数中的“”上下文不清楚

Javascript `构造函数中的“”上下文不清楚,javascript,constructor,Javascript,Constructor,我想要的是一个具有值(clazz)和函数(test)的对象,函数在其中传递值 我想要:xyz 我得到:TypeError:Construct不是构造函数您的Clazz函数不返回构造函数。我想你真的想要这样的东西 function Construct() { Clazz.call(this, { clazz : "xyz", test : function () { console.log(this.clazz);

我想要的是一个具有值(clazz)和函数(test)的对象,函数在其中传递值

我想要:
xyz


我得到:
TypeError:Construct不是构造函数

您的
Clazz
函数不返回构造函数。我想你真的想要这样的东西

function Construct() {
    Clazz.call(this, {
        clazz : "xyz",
        test  : function () {
            console.log(this.clazz);
       }
    });
}
function Construct() {
    Clazz.call(this, {
        clazz : "xyz",
        test  : function () {
            console.log(this.clazz);
       }
    });
}