Skip to content

Instantly share code, notes, and snippets.

@hernandohhoyos
Created July 26, 2024 20:53
Show Gist options
  • Save hernandohhoyos/8f8ea13fa5d085b8f10051e97ab6a297 to your computer and use it in GitHub Desktop.
Save hernandohhoyos/8f8ea13fa5d085b8f10051e97ab6a297 to your computer and use it in GitHub Desktop.
imlementación que permite llamar funciones pasando el propio objeto como contexto
let schema = {
type: Number,
min: 1900,
max: () => new Date().getFullYear(),
message: () => {
if(typeof this.max === 'function'){
return `El valor debe estar entre ${this.min} y ${this.max()}`
}
return `El valor debe estar entre ${this.min} y ${this.max}`
}
}
if(typeof schema.message === 'function'){
console.log(new Function(`return ${schema.message}`).call(schema)())
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment