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

161
Views
'TypeError: ¿No se puede establecer la propiedad 'crear' de indefinido'?

Estoy tratando de crear un método prototipo para un objeto "Usuario". ¿Cómo es "crear" indefinido cuando literalmente lo declaro a una función?

 const mongoose = require("mongoose") const userSchema = new mongoose.Schema({ username: { type: String, required: [true, "Field cannot be left blank"], unique: [true, "That username is already taken"], minlength: [3, "Username must be at least 3 characters"], maxlength: [15, "Username cannot exceed 15 characters"], }, }) const Doc = new mongoose.model("user", userSchema) let User = (username) => { this.username = username } User.prototype.create = function () { return new Promise(async (resolve, reject) => { try { let doc = await new Doc({ username: this.username, }) resolve(doc) } catch (err) { reject(err) } }) } module.exports = User
about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

Pude resolverlo cambiando la función de flecha de mi constructor a una función anónima. Investigué un poco y ES6 no permite que las funciones de constructor sean funciones de flecha.

 //previous code let User = (username) => { this.username = username } //correct code let User = function(username) { this.username = username }
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!