我在 EcmaScript 规范中读到某些方法是 "generic"。这是什么意思?
I read in the EcmaScript specification that certain methods are "generic". What does this mean?
我在 EcmaScript 规范中读到某些方法是 "generic"。这是什么意思?
这是否意味着在调用函数时,这些方法对绑定到 this
值的对象几乎没有做出任何假设?
在面向对象编程中,泛型函数是使用其参数类型自动运行最合适方法的函数。来自 EcmaScript draft:
Generic functions are function objects each with a set of attached methods. A call to a generic function matches the types of the actual arguments to the signatures of the attached methods and dispatches to the most appropriate method following deterministic rules.
Does it mean that the methods make little or no assumptions about the object bound to the this value when the function is invoked?
正是这样。每当您阅读术语 "generic method"、"intentionally generic" 或 "not generic" 时,都会明确指定该函数是通用的(或不是通用的):this
值(接收方)是一个具有特定内部插槽的某种对象。 (示例是类型化数组方法)
泛型方法不使用此类并且在找不到它们时不抛出,而是它们仅使用 public(泛型 "object interface")属性(示例是数组方法),或者将值转换为他们期望的类型(例如字符串方法)。
我在 EcmaScript 规范中读到某些方法是 "generic"。这是什么意思?
这是否意味着在调用函数时,这些方法对绑定到 this
值的对象几乎没有做出任何假设?
在面向对象编程中,泛型函数是使用其参数类型自动运行最合适方法的函数。来自 EcmaScript draft:
Generic functions are function objects each with a set of attached methods. A call to a generic function matches the types of the actual arguments to the signatures of the attached methods and dispatches to the most appropriate method following deterministic rules.
Does it mean that the methods make little or no assumptions about the object bound to the this value when the function is invoked?
正是这样。每当您阅读术语 "generic method"、"intentionally generic" 或 "not generic" 时,都会明确指定该函数是通用的(或不是通用的):this
值(接收方)是一个具有特定内部插槽的某种对象。 (示例是类型化数组方法)
泛型方法不使用此类并且在找不到它们时不抛出,而是它们仅使用 public(泛型 "object interface")属性(示例是数组方法),或者将值转换为他们期望的类型(例如字符串方法)。