Skip to content

Generator에서 for-in 사용시 hasOwnProperty 필요 여부 #1

Closed
@Jeewhan

Description

@Jeewhan

안녕하세요, 인동님.

너무나 좋은 글, 감사히 읽고 있습니다.

글을 보다가 궁금한 점이 생겨서 질문을 드리고 싶습니다


링크 1에 나오는 아래 코드에 대한 질문입니다.

function *valuesIter(obj) {
  for (const key in obj) yield obj[key];
}
const users = {
  5: { id: 5, name: 'YB' },
  19: { id: 19, name: 'BX' },
  27: { id: 27, name: 'MD' }
};
for (const val of valuesIter(users)) log(val.name);
// YB
// BX
// MD

링크 2에도 유사한 코드가 있습니다

Object.assign(ObjIter, {
  values: ObjIter(function *(coll) {
    if (!coll) return;
    for (const key in coll) yield coll[key];
  }),
  entries: ObjIter(function *(coll) {
    if (!coll) return;
    for (const key in coll) yield [key, coll[key]];
  })
});

Generator 내부에서 for-in을 사용하고 있는데, hasOwnProperty에 대한 체크는 필요하지 않은지 여쭙고 싶습니다.


함수형에 관하여 좋은 콘텐츠들을 거듭 제공해주셔서, 늘 감사드립니다!

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions