Javascript 在 CoffeeScript 中 for (var key in object)?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/6433207/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-23 21:42:30 来源:igfitidea点击:
for (var key in object) in CoffeeScript?
提问by fancy
How can I use for (var key in object) in CoffeeScript? It compiles to...
如何在 CoffeeScript 中使用 for (var key in object)?它编译为...
for (_i = 0, _len = object.length; _i < _len; _i++) {
key = object[_i];
...but I just want to iterate though an object.
...但我只想遍历一个对象。
回答by Raynos
回答by Mark Kahn
of
keyword:
of
关键词:
for key, value of obj
or to make sure you're only checking properties on this object (and not the prototype chain):
或者确保您只检查此对象的属性(而不是原型链):
for own key, value of obj