问题标签 [language-concepts]
For questions regarding programming in ECMAScript (JavaScript/JS) and its various dialects/implementations (excluding ActionScript). Note JavaScript is NOT the same as Java! Please include all relevant tags on your question; e.g., [node.js], [jquery], [json], [reactjs], [angular], [ember.js], [vue.js], [typescript], [svelte], etc.
java - 递归编程调用与动态编程调用
我正在学习 Java 2 课程并尝试学习,但我不明白这个概念:
递归编程调用和动态编程调用有什么区别?
每个的例子是什么?
c# - myCustomDictionary.Values 应该返回什么类型?
如果你有对象Dictionary<k, v> myDictionary
,那么myDictionary.Values
将是类型Dictionary<k, v>.ValueCollection
并且myDictionary.Keys
将是类型Dictionary<k, v>.KeyCollection
。
我不明白为什么类型myDictionary.Values
不是类似IEnumerable<v>
,IList<v>
或其他东西。
现在,考虑到这一点,如果我创建一个自定义类型的字典;Dictionary2<k1, k2, v>
,应该myCustomDictionary.Values
返回IEnumerable<v>
ValueCollection 的,还是自定义实现?更重要的是,为什么?
python - python中的抽象方法和mixin
我想提交一个我经常在我的python代码中看到的代码模式,在这里工作,我对它不满意,我想要一个更好的解决方案。
这是我们今天的内容:
你看到诀窍了吗?我必须在继承列表的第一个位置添加 mixin,我不喜欢这个解决方案。如果我们将它添加到第二个位置,解释器将使用 AbstractClass.method1 并因此引发异常。
在这种微不足道的情况下,用中间类替换 mixin 是可能的,但在已经有基类的复杂继承的情况下,解决方案可能并不明显。
对你来说最好的设计模式是什么?
javascript - 澄清 JavaScript 原型
假设我有一个子函数:
并有一个父函数:
然后我将 Child 的原型设置为 Parent 的新实例:
困惑是每次我创建新的 Child 实例时
是否会再次创建父级?
java - 如何使用 HashTable 检索另一条语句记录?
晚上好,我尝试使用 HashTable() 临时存储数据库表记录。问题是我不知道为什么放在 HashTable() 中的记录总是第一条记录。我认为问题的出现是因为错误的循环概念,相关代码:
宣布
for 循环
p / s:我是HashTable的新手,db(数据库语句)运行良好......
需要一些提示和建议,谢谢先进^^
ios - iOS >> 协议和委托概念
网上有很多关于 Protocols & Delegates 的资料,不同的教程用不同的名字称呼这个过程中的一些“参与者”。
特别令人困惑的是“Adaptor”和“Conformer”的概念。
我了解实现协议方法的类 - 即其中包含<ProtocolName>
声明的类 - 是“符合协议”。它也是协议的“采用者”吗?
如何调用在其中声明或重新声明协议的类,以便它可以包含必须符合协议的属性 - 即在其接口中具有@protocol ProtocolName
声明?
我找不到任何解释这一点的 Apple 官方文档。
编辑
伙计们,感谢指定的答案,但我确实(并且确实)理解了这种模式以及它是如何在语言中实现的。我的问题是(并且仍然是)与 NAMING 相关......而且,我仍然找不到任何关于“声明/重新声明协议的类的名称(概念上)是什么”的参考。也许它没有名字,我应该称之为:“声明/重新声明协议的类”。也许我可以称它为“委托类”(顺便说一句,这听起来不错)......
naming - 错误和警告的常用术语是什么?
我想构建一个在定价操作期间返回给客户端的错误和警告的 OO 层次结构:
我对这个名字不是很感兴趣PricingMessage
。包含错误和警告的概念是什么?
编辑:明确地说,我正在寻找一个常见的概念或名称来专门用于错误和警告(不包括例如一般信息消息)。例如,编译器也会报告错误和警告。这些是什么?
c++ - 也检查指针或引用类型的 C++ dynamic_cast 的设计考虑
当我们进行动态转换时:
只有在以下情况下,dynamic_cast 才会返回有效指针:
- A 是多态的,否则编译失败。
B 等价于 A 或者从 A 派生B 应该在继承层次结构中与 A 有关系(虽然我不确定策略),否则返回 nullptr。这是根据评论更新的。- *x 的 RTTI 表明它是 B 类的对象或 B 的派生类,否则返回 nullptr。
我正在考虑同时满足条件 1 和条件 3 的情况,但条件 2 除外。由于内存复制或 reinterpret_cast 等原因,这可能是可能的。以下所有讨论均基于此场景。
一个小例子在这里:http: //ideone.com/tBctgT
我可以这样说:如果在这种情况下 C++ 允许 dynamic_cast 成功,那么使用 dynamic_cast 返回的指针仍然是安全的吗?如果是这样,为什么 C++ 标准确定条件 2 的验证是强制性的?
此外,可以在编译时检查条件 2。为什么 C++ 标准决定在运行时返回 nullptr 而不是给出编译错误,如果它不被认为是正确的操作?
go - “点括号”语法的含义是什么?
我正在研究一个将数据存储在 mongodb 中的示例 Go 应用程序。这一行的代码(https://github.com/zeebo/gostbook/blob/master/context.go#L36)似乎访问了存储在大猩猩会话中的用户ID:
有人可以向我解释一下这里的语法吗?我知道这sess.Values["user"]
会从会话中获得价值,但接下来的部分是什么?为什么括号中的点后面的表达式?这是函数调用吗?
java - Studying Objects and Classes
I have a test later today, and I think I may be stuck on this part of the study guide:
Classes and objects, references, methods; the class as a pattern for creating objects, the concept of a class and object as defining a unit with data members and methods; what is an instance of a class; static members of a class; what it means for a member of class to be public
My best effort to explain these concepts is, as follows:
A class is a programmer defined data type that is composed of data members and methods.
An object is an entity consisting of values (characteristics and traits) and methods (capabilities or behaviors). A class is like a blueprint from which objects are created.
A reference variable points to an object created in another memory location. (not 100% sure what this means)
Much like a cookie cutter can be used to create individual cookies, a class can be used to create individual objects, or instances of that class.
A static member of a class (or class variable or method) belongs to the class and is not owned by any object of the class.
If a member of a class is public, that means that it can be accessed by other parts of the program.
I'm wondering if this is going to be satisfactory or if I'm missing anything critical. Obviously I'm shaky on the idea of reference and reference variables, and I think I'm still trying to conceptualize objects and classes in a way that's sufficiently explainable.
Thanks for your help, in advance.