我有一个TypeError问题:
function artist(name) {
this.name = name;
this.albums = new Array();
this.addAlbum = function(albumName) {
for (var i = 0; i < this.albums.length; i++) {
if (this.albums[i].name == albumName) {
return this.albums[i];
}
}
var album = new album(albumName);
this.albums.push(album);
return album;
}
}
function album(name) {
this.name = name;
this.songs = new Array();
this.picture = null;
this.addSong = function(songName, track) {
var newSong = new songName(songName, track);
this.songs.push(newSong);
return newSong;
}
}
Run Code Online (Sandbox Code Playgroud)
给出以下错误:
TypeError: album is not a constructor …
我在ES6目标环境中运行以下打字稿代码,它说"汽车不是构造函数"
我已经按照链接尝试将目标环境更改为ES5.它工作正常.有人可以说明为什么它不适用于目标ES6.
这是我的TypeScript代码:
export class Cars {
constructor(public len: number,public wid: number) { }
}
export function getSize(): Cars {
return new Cars(20, 30);
};
Run Code Online (Sandbox Code Playgroud)
函数getSize中的错误是"汽车不是构造函数".
顺便说一下,我试图用Systemjs加载所有文件.
顺便说一句,我在浏览器中收到错误........而不是在编译时......
这是上面打字稿的编译代码....
System.register([], function(exports_1, context_1) {
"use strict";
var __moduleName = context_1 && context_1.id;
var Cars;
function getSize() {
return new Cars(20, 30);
}
exports_1("getSize", getSize);
return {
setters:[],
execute: function() {
class Cars {
constructor(len, wid) {
this.len = len;
this.wid = wid;
}
}
;
exports_1("Cars", Cars);
}
} …Run Code Online (Sandbox Code Playgroud)