Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

function.caller 被认为是有害的 #3393

Merged
merged 4 commits into from Mar 8, 2018
Merged

function.caller 被认为是有害的 #3393

merged 4 commits into from Mar 8, 2018

Conversation

yankwan
Copy link
Contributor

@yankwan yankwan commented Mar 7, 2018

function.caller 被认为是有害的

译文翻译完成,resolve #3379

function.caller 被认为是有害的
@Starriers
Copy link
Contributor

校对认领

@fanyijihua
Copy link
Collaborator

@Starriers 好的呢 🍺

Copy link
Contributor

@Starriers Starriers left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@leviding @yankwan 校对完成


Today I received this question from Microsoft’s Patrick Kettner, which I realized is a question that I answered fairly often already, but usually in a slightly different form.
今天我收到来自微软的 Patrick Kettner 提的这个问题,然而我发现这个问题是我已经回答过的,只不过是以稍微不同的方式回答而已。
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

『只不过是以稍微不同的方式回答而已』=>『只不过是每次的问题稍有不同』
同一个问题用稍有不同的方式回答 ,逻辑不会奇怪么。
我觉得 answer 并不是句子的主语,question 才是。


So “caller” property of sloppy mode function is more or less completely implementation defined behavior. The only restriction is that if it yields a value, then that value must not be a strict mode function. So it’d be perfectly valid to install a value 42 as default “caller” on sloppy mode functions. Obviously implementations don’t do that — although it’s tempting to add that to V8 to really discourage everyone from using foo.caller nowadays.
所以在非严格模式函数下的 "caller" 属性,或多或少完全实现了既定的行为。唯一的限制是如果有 yield 一个变量,那么这个变量一定不是严格模式下的函数。所以在非严格模式下,给 "caller" 赋一个默认值 42 是一个合理做法。显然实现中并没有这么做 —— 尽管有把这个添加到V8中的想法,同时现在也极不建议大家使用 foo.caller
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

『V8』=>『 V8 』前后少了空格,下面的也是,不重复提示了


* * *

So here’s how we currently implement the (mis)feature in V8 — and thereby how it works in Chrome and Node.js. The “caller” property on sloppy mode functions is a special accessor [FunctionCallerGetter](https://cs.chromium.org/chromium/src/v8/src/accessors.cc?type=cs&l=1044) implemented in accessors.cc, with the core logic being [FindCaller](https://cs.chromium.org/chromium/src/v8/src/accessors.cc?type=cs&l=1000) in the same file. It’s arguably difficult to understand the underlying rules, so here’s what we do in a nutshell when you access foo.caller for a sloppy mode function foo:
这是我们目前如何在V8中实现这些(有误导性的)特性 —— 也正是如何在谷歌浏览器和 Node.js 中运行的。"caller" 这个属性在非严格模式函数中是一个特殊的访问器,其实现方法 [FunctionCallerGetter](https://cs.chromium.org/chromium/src/v8/src/accessors.cc?type=cs&l=1044) accessors.cc 源码文件中实现,同时在该文件实现的还有核心的逻辑方法 [FindCaller](https://cs.chromium.org/chromium/src/v8/src/accessors.cc?type=cs&l=1000)。要理解下面这些规则可以说是比较困难的,但这就是当你在非严格模式下访问 foo.caller时我们底层代码所做的事:
Copy link
Contributor

@Starriers Starriers Mar 7, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

『谷歌浏览器』=>『Chrome』
专有名词 不要翻译

@yankwan
Copy link
Contributor Author

yankwan commented Mar 7, 2018

@leviding 已经根据校对进行修改

@leviding leviding merged commit 75b4dbe into xitu:master Mar 8, 2018
@leviding
Copy link
Member

leviding commented Mar 8, 2018

@yankwan 已经 merge 啦~ 快快麻溜发布到掘金然后给我发下链接,方便及时添加积分哟。

掘金翻译计划有自己的知乎专栏,你也可以投稿哈,推荐使用一个好用的插件
专栏地址:https://zhuanlan.zhihu.com/juejinfanyi

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

function.caller 被认为是有害的
4 participants