這個前面的討論:Inheritance TypeScript with exported class and modules繼承與打字稿不工作的瀏覽器端
這是從ValidatorMessage.class.ts生成的源:
///<reference path='./def/lib.d.ts'/>
///<reference path='./def/node.d.ts'/>
var __extends = this.__extends || function (d, b) {
for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p];
function __() { this.constructor = d; }
__.prototype = b.prototype;
d.prototype = new __();
};
var message = require("./Message.class");
var ValidatorMessage = (function (_super) {
__extends(ValidatorMessage, _super);
function ValidatorMessage() {
_super.apply(this, arguments);
}
return ValidatorMessage;
})(message.Message);
exports.ValidatorMessage = ValidatorMessage;
但是,當我上加載它瀏覽器(Grunt.js合併和縮小後),我得到這個錯誤:
未捕獲TypeError:無法讀取未定義的屬性'原型'
行剛過:
__.prototype = b.prototype, d.prototype = new __();
(〜LIGNE 6 & 7)
我不明白這個錯誤。即使我只將TS生成的源代碼放在Grunt中,我也會得到相同的錯誤。
編輯:
的console.log(消息):
function Message(message, data, status) {
"undefined" == typeof data && (data = !1), "undefined" == typeof status && (status = !1),
/**
* Constants.
*/
this.FIELD_NAME_MESSAGE = "m", this.FIELD_NAME_DATA = "d", this.FIELD_NAME_STATUS = "s",
this.EXCEPTION_BAD_JSON_CONTENT = 'Unable to parse JSON. Bad object/string attributes. (Missing message ("' + this.FIELD_NAME_MESSAGE + '" field) or status ("' + this.FIELD_NAME_MESSAGE + '" field)?',
this.EXCEPTION_BAD_JSON_TYPE = "Incorrect data type. Object or string expected.",
this._message = message, this._data = data, this._status = status;
}
什麼是行之後消息:'VAR消息=要求( 「./ Message.class」);'你可以CONSOLE.LOG(消息)在Chrome或者Firefox來記錄它並看到它的價值。它應該是一個函數,所以你可以'console.log(typeof message);'看看它是否是一個函數。 – HMR
主編編輯。這是一個功能。我寫了這個函數需要我自己,因爲它之前不存在:require = function(file)var files = file.split('/'); file = files [files.length - 1] .replace('。class',''); 返回導出[文件] ||窗口[文件]; } – Vadorequest
最後,我使用了requireJs和AMD編譯標誌,它正在工作。 – Vadorequest