我读过EcmaScript规范,某些方法是“通用的”。这是什么意思? [英] I read in the EcmaScript specification that certain methods are "generic". What does this mean?

查看:82
本文介绍了我读过EcmaScript规范,某些方法是“通用的”。这是什么意思?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我读了EcmaScript规范,某些方法是通用的。这是什么意思?



这是否意味着这些方法对绑定到的对象做出很少或根本没有假设这个调用函数时的值?

解决方案


这是否意味着方法很少或没有当函数被调用时,关于绑定到该值的对象的假设?


正是这样。每当您阅读术语通用方法,有意通用或不通用时,明确指出该函数是通用的(否则):值(接收器)是具有特定内部插槽的某种对象。 (例子是类型化的数组方法)



通用方法不使用这种方法,不会在没有找到它们的情况下抛出,而是只使用public(通用的对象接口)属性(例子是数组方法),或者转换为期望类型的值(例子是字符串方法)。


I read in the EcmaScript specification that certain methods are "generic". What does this mean?

Does it mean that the methods make little or no assumptions about the object bound to the this value when the function is invoked?

解决方案

Does it mean that the methods make little or no assumptions about the object bound to the this value when the function is invoked?

Exactly that. Whenever you read the term "generic method", "intentionally generic" or "not generic", it is explicitly specified on what that function is generic (or not): the this value (receiver) being an object of a certain kind, with specific internal slots. (examples are typed array methods)

Generic methods do not use such and do not throw when they don't find them, instead they use only the public (generic "object interface") properties (examples are array methods), or cast values to type they expect (examples are string methods).

这篇关于我读过EcmaScript规范,某些方法是“通用的”。这是什么意思?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆