我需要在JS中编写一些扩展方法。我知道如何在C#中做到这一点。示例:
public static string SayHi(this Object name)
{
return "Hi " + name + "!";
}
然后调用:
string firstName = "Bob";
string hi = firstName.SayHi();
我该如何在JavaScript中做这样的事情呢?
发布于 2020-09-21 19:54:35
declare global {
interface DOMRect {
contains(x:number,y:number): boolean;
}
}
/* Adds contain method to class DOMRect */
DOMRect.prototype.contains = function (x:number, y:number) {
if (x >= this.left && x <= this.right &&
y >= this.top && y <= this.bottom) {
return true
}
return false
};
https://stackoverflow.com/questions/9354298
复制相似问题