Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

206
Views
¿Puedo Symbol.iterator en Object por prototipo?"JavaScript"

¿Por qué no puedo agregar Symbol.iterator en un objeto como ese?

 Object.prototype[Symbol.iterator]; let obj = {num: 1 , type : ' :) '} for (let p of obj) { console.log(p); } // TypeError: obj is not iterable
about 4 years ago · Juan Pablo Isaza
2 answers
Answer question

0

Debe asignar una función de generador a Object.prototype[Symbol.iterator] .

 Object.prototype[Symbol.iterator] = function*() { for (let k in this) { yield this[k]; } }; let obj = { num: 1, type: ' :) ' } for (let p of obj) { console.log(p); }

about 4 years ago · Juan Pablo Isaza Report

0

Porque en realidad no asignó nada a Object.prototype[Symbol.iterator] : si asigna una función de iterador que hace algo sensato, creo que podría funcionar como esperaba

 Object.prototype[Symbol.iterator] = function*(){ for(let entry of Object.entries(this)) yield entry }; let obj = {num: 1 , type : ' :) '} for (let [k,v] of obj) { console.log(k,v); } // another way console.log(...obj)

about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!