Hi , i have one question what s The .require() of javascript and Thank you .
Can you elaborate on your question more?
thank you for reply, what is .require () in, javascript
let myModule={
add: function (){
console.log("add module" )
}
}
Object.prototype.requires=function(a){
let b
//this==myModule which is true
for(let i in this){
if(i===a){
b=this
return Object.values(b)[0]
}
}
}
let b=myModule.requires("add")
console.log(b())
//result
//add module
The method requires do the same job which
require method do. This require method is used to import some method from module.
The code i wrote above in which i have a module called myModule . In myModule I have a method called add. I have to invoke my method add.
To invoke add, i can use below code
myModule.add()
Here you know that myModule is the variable name which i used to assing the value of object. What if you don’t know the value of variable and you have to import some package from module. Then you have to use . require method
Thank you very match .