繁体   English   中英

使用TypeScript扩展Element原型

[英]Extend Element prototype using TypeScript

鉴于下面的javascript,是否有相应的TypeScript做同样的事情?

我只需要扩展html dom元素原型,但无法在没有编译错误的情况下找出正确的TypeScript。

Element.prototype.astyle = function actualStyle(props) {
    var el = this;
    var compStyle = window.getComputedStyle(el, null);
    for (var i = 0; i < props.length; i++) {
        var style = compStyle[props[i]];
        if (style != null) {
            return style;
        }
    }
    return null;
};

您需要先使用interface来扩展Element。

interface Element{
    astyle(props:string[]);
}

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM