是否可以在 Haxe 中覆盖 js.html.Window class 的函数?
Is it possible to override a function of js.html.Window class in Haxe?
我正在尝试移植一些代码从JS到Haxe。
代码覆盖 Window.getComputedStyle 以解决 Firefox 问题 (Bugzilla link):
window.oldGetComputedStyle = window .getComputedStyle;
window.getComputedStyle = function (element, pseudoElt) {
var t = window.oldGetComputedStyle(element, pseudoElt);
if (t === null) {
return {};
} else{
return t;
}
};
我该如何解决这个问题?
当我尝试时,出现以下错误:
Cannot rebind this method : please use 'dynamic' before method declaration
我找到了解决办法。
我需要将 Window
分配为 untyped
以绕过编译器错误:
iframe = cast Browser.document.getElementById("iframe");
var window = untyped iframe.contentWindow;
var oldGetComputedStyle = window.getComputedStyle;
window.getComputedStyle = function (element, pseudoElt) {
var t = oldGetComputedStyle(element, pseudoElt);
if (t == null) {
return {};
} else{
return t;
}
}
我正在尝试移植一些代码从JS到Haxe。
代码覆盖 Window.getComputedStyle 以解决 Firefox 问题 (Bugzilla link):
window.oldGetComputedStyle = window .getComputedStyle;
window.getComputedStyle = function (element, pseudoElt) {
var t = window.oldGetComputedStyle(element, pseudoElt);
if (t === null) {
return {};
} else{
return t;
}
};
我该如何解决这个问题?
当我尝试时,出现以下错误:
Cannot rebind this method : please use 'dynamic' before method declaration
我找到了解决办法。
我需要将 Window
分配为 untyped
以绕过编译器错误:
iframe = cast Browser.document.getElementById("iframe");
var window = untyped iframe.contentWindow;
var oldGetComputedStyle = window.getComputedStyle;
window.getComputedStyle = function (element, pseudoElt) {
var t = oldGetComputedStyle(element, pseudoElt);
if (t == null) {
return {};
} else{
return t;
}
}