它是关于MDN页面中的JS类的。我不明白为什么坏类有一个引用错误。这是因为Bad类的空构造函数作为默认值调用super()吗?
class Base {}
class Good extends Base {}
class AlsoGood extends Base {
constructor() {
return {a: 5};
}
}
class Bad extends Base {
constructor() {}
}
new Good();
new AlsoGood();
new Bad(); // ReferenceError
我使用角4创建我的网站。但是我需要创建一个对象,里面有一个对象向量。这对我没用。我的守则:
对象1 (disciplinaStatus.module.ts)
export class DisciplinaStatus{
constructor(public codigo: string,
public nome: string,
public status: string,
public professor:string,
public cargaHoraria:string,
public
这是我尝试构建的第一个外部JavaScript“模块”。我正在使用Babylon.js创建一个空间场景。我的库本身没有问题。这与我对使用模块不理解有关。我想做的是把一个构造函数放在另一个文件中。这个构造函数的实例将创建我设计的星形网格。如果我把构造函数放在文件中,它就能工作。如果我把它放在另一个名为Star.js的文件中,然后把它放在页眉中的脚本标签中,页面就会加载空白。
我还试着用我读过的匿名函数的各种模式把它放在括号里……这似乎无关紧要,我想不管怎样,它应该可以工作。
以下是文件中的内容...(未包装)
var Star = function (position) {
this.spher
是的,以前有人问过这个问题,但是 为我工作。
在调用TypeError: Config is not a constructor构造函数时,我将得到一个Config。通过其他这样的问题和,这个错误的常见原因似乎要么是隐藏构造函数,要么是调用不可调用的类型,但在我的项目中这两个都没有签出。
这就是号召:
var Server = require("./server.js").Server;
var Config = require("./config.js").Config;
new Server(new Config("app/config.json
当我使用new来阻止某个类的实例时,我得到了实际的实例。当构造函数有一个返回值时,new语句也会给出实际实例。但是,当构造函数本身返回时,我无法获得实例。相反,我得到构造函数。我想知道这是怎么回事。
下面是我的测试代码片段:
function foo() {
this.x = 1;
return foo;
}
console.log(new foo()); // prints the defination of foo
正如我们所考虑的,在大多数情况下,返回这样的函数是没有意义的。然而,为什么JS会有这样的特性呢?在设计JS时有考虑吗?还是仅仅是JS的一个bug?
最近我开始学习Box2D引擎。我偶然发现了一个错误,却找不到原因。从firebug控制台: TypeError:groundBd.AddShape不是一个函数。groundBd.AddShape(groundSd);
以防万一,下面是我正在读-js文件的那本书的代码-
var carGame = {
}
var canvas;
var ctx;
var canvasWidth;
var canvasHeight;
$(function() {
// create the world
carGame.world = createWorld();
//
我一直试图得到一个看似简单的例子,但一直未能使用MobX、React、TypeScript和actions。没有严格,一切正常,但我宁愿使用严格的模式。
我得到的错误是:
Uncaught Error: [mobx] Since strict-mode is enabled, changing observed observable values outside actions is not allowed. Please wrap the code in an `action` if this change is intended. Tried to modify: AppState@1.t
TypeError: Produto is not a constructor
at exports.create (C:\Users\mathe\Documents\TESTES\todoList\back-end\src\controllers\produtos.controller.js:18:4)
at Layer.handle [as handle_request] (C:\Users\mathe\Documents\TESTES\todoList\back-end\node_modules\express\lib\router\layer.js:95:5)
class A{
constructor(){
this.name="A";
}
M1(){
return "M1";
}
}
class B extends A{
constructor(){
this.id="B";
}
M2(){
return "M2";
}
}
var b = new B();
输出:
ReferenceError:这不是定义在B(爬虫:4:1)在REPLServer.de
我看到了著名的JS的extend函数:
function extend(parent, child) {
var F = new Function();
F.prototype = parent.prototype;
child.prototype = new F();
//child.prototype.constructor = Child
}
我已经注释掉了重写构造函数属性的行。如果我以下列方式创建对象:
var p = function p() {this.parent = true};
var c = function c() {this.child
我们有循环依赖结构,这在逻辑上应该是好的。灯光导入导入NodeManager的节点,反过来又导入灯光。当运行我们的代码时,我们得到以下结果
"Super expression must either be null or a function"
NodeManager
// in NodeManager.js
import Light from '../../Light.js'
class NodeManager {
static _instance;
static getInstance() {
if(NodeManager._instanc
如果new A()和new B()都是幂等的,那么如果new B(); new A();成功了,new A(); new B();会不会总是成功呢?
下面的内容会产生一个令人困惑的错误(因为我并不试图引用host,而是将其作为参数提供给B,B作为构造函数参数):
#app.js
const DEFAULT_HOST = "localhost";
class B {
constructor(host = null) { console.log(`HOST: ${host}`); }
}
class A {
constructor() { new B(host
我正在制作一个将信息发送到数据库的表单,以便学习使用Angular6和Firebase进行CRUD操作,但是当我提交它时,我得到:
AddNewAnimalComponent.html:5 ERROR TypeError: Cannot read property 'push' of undefined
at AnimalsService.push../src/app/animals.service.ts.AnimalsService.insertAnimal (animals.service.ts:32)
at AddNewAnimalComponent.pu
在JavaScript中,函数声明是创建可用于实例化新对象的构造函数的唯一方法。如果是,为什么?此问题源于以下代码。
var customevent = {
prop1 : "div",
prop2 : "div2"
}
var myevent_obj = new customevent();
浏览器JS控制台显示
SyntaxError: customevent is not a constructor.