Created
July 26, 2024 20:53
-
-
Save hernandohhoyos/8f8ea13fa5d085b8f10051e97ab6a297 to your computer and use it in GitHub Desktop.
imlementación que permite llamar funciones pasando el propio objeto como contexto
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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