简体   繁体   English

类定义javascript中的for循环

[英]For loop in a class definition javascript

Recently I ran into some code that basically looks like : 最近,我遇到了一些基本上看起来像这样的代码:

class A {
  constructor(opts) {
    this.a = {};
  }

  for(x, y) {
   ...

    return {
      async check(id) {
        ... 
      }
   };
  }
...more method definitions in the class
}

I'm wondering how its possible to put a for loop inside a class definition . 我想知道如何在类定义中放入for循环。 I can see that it is returning a function, but does this mean that the returned function becomes a member function for the class? 我可以看到它正在返回一个函数,但这是否意味着返回的函数成为该类的成员函数?

It's not a for loop, it's a method named 'for'. 这不是for循环,而是一个名为“ for”的方法。

More or less equivalent to 或多或少相当于

A.prototype.for = function for( x, y ) {
    ...
    return {
      async check(id) {
        ... 
      }
   };
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM