我試圖將此添加到.ts文件的底部,但是我在VS2012 [如果(!Object.construct)]構建並擴展了一個錯誤[]沒有定義。解決方案?瀏覽器兼容性代碼不能在ts中編譯
if (!Object.construct) {
Object.construct = function(base) {
var instance = Object.create(base);
if (instance.initialize)
instance.initialize.apply(instance, [].slice.call(arguments, 1));
return instance;
}
}
if (!Object.extend) {
Object.extend = function(destination, source) {
for (var property in source) {
if (source.hasOwnProperty(property))
destination[property] = source[property];
}
return destination;
};
}
嘗試這樣做:
interface Object {
extend(destination, source): any;
construct(base): any;
}
class Game { etc//
真棒,這非常感謝 – Nikos 2013-03-25 16:39:39
嗯.. doesn' t似乎工作,仍然得到相同的錯誤 – Nikos 2013-03-25 17:16:51
你把接口放在一個模塊裏面嗎?它適用於我,這是我能想到的唯一原因。 – 2013-03-25 17:30:44