- Java 双重比较
- java - 比较器与 Apache BeanComparator
- Objective-C 完成 block 导致额外的方法调用?
- database - RESTful URI 是否应该公开数据库主键?
我正在尝试对 Set 对象执行一些基本操作,如 here 所说
这是代码
export class Conjunto extends Set<any>{
constructor(initialValues?) {
super();
return new Conjunto(initialValues);
}
isSuperset(subset) {
//some code
}
}
你们有什么想法让它发挥作用吗?还是我做错了什么?
目前我正在使用这个人发现的 hack here
最佳答案
如果您尝试向 Set 原型(prototype)添加函数,或向 Set 添加 polyfill,您可以执行以下操作:
declare global {
interface Set<T> {
// polyfill
isSuperset(subset: Set<T>) : boolean;
// new function
someNewFunc(): boolean;
}
}
// add polyfill to the Set prototype as mentioned in the doc you provided: https://developer.mozilla.org/es/docs/Web/JavaScript/Referencia/Objetos_globales/Set
Set.prototype.isSuperset = function(subset) {
for (var elem of subset) {
if (!this.has(elem)) {
return false;
}
}
return true;
}
//add the new someNewFunc;
Set.prototype.someNewFunc = function() {
// some logic here...
return true;
}
使用:
stringSet = new Set<string>()
stringSet.isSuperset(someOtherSet);
stringSet.someNewFunc(); // returns true
关于javascript - typescript :在类中扩展集会导致错误(构造函数集需要 'new' ),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43301849/
这些指令有什么区别?以 ARM9 处理器为例,它不应该是: ASM: mov r0, 0 C: r0 = 0; ASM: ld r0, 0 C: r0 = 0; ? 我不知道为什么要使用一个或另一个:
快速提问,我正在阅读 Richard C. Detmer 编写的题为“80x86 汇编语言和计算机体系结构简介”的教科书,第 21 和 22 页谈到了借用的概念,但它并没有真正描述什么确实如此。以下是
我想不通为什么我的程序会在我希望它在 ecx 的值等于 0 后退出时进入无限循环?请帮忙? section .data ;get external functions extern printf gl
我的解决方案中有 2 个项目: 程序集(基本库) 测试程序集(NUnit) 我在第一个项目中将测试程序集声明为 friend 程序集: [assembly: InternalsVisibleTo ("
我的解决方案中有 2 个项目: 程序集(基本库) 测试程序集(NUnit) 我在第一个项目中将测试程序集声明为 friend 程序集: [assembly: InternalsVisibleTo ("
我几周前通过的单元测试现在失败了。当单元测试尝试创建工作空间权限时,现在会失败。我使用相同的 api-key,它具有订阅级别的访问权限,因此授权不是问题。以下是当我尝试创建工作空间权限时 WSAPI
使用集会 Node 工具包,当我尝试将新的变更集(带有新的内联变更)添加到现有的用户故事时,我收到返回的错误消息。当我注释掉新的更改时,更改集会按预期添加。这似乎与我无法弄清楚的更改数据有关。 添加通
我是 Rally 世界的新手,正在努力了解如何使用 RallyRestAPI。有许多示例说明如何查询 Rally 以获取我认为最有帮助的相关信息。我想要做的是创建一个 C# 命令行工具来将用户添加到项
尝试运行对集会的读取调用时,我不断从 Node 收到以下错误响应: Error: getaddrinfo ENOTFOUND rally1.rallydev.com rally1.rallydev.c
我正在尝试使用 python 工具包查询特定迭代中的所有任务以进行集会 REST API .迭代将在运行时选择。 但是我无法设置正确的查询。我觉得我在这里遗漏了一些小而重要的东西。 这是代码: que
我正在通过 Ruby 使用 Rally API ( http://developer.help.rallydev.com/ruby-toolkit-rally-rest-api-json )。我想查询
我是一名优秀的程序员,十分优秀!