I am new to Node.js and I am trying to run this simple program:
var AwesomeClass = function() {
this.awesomeProp = 'awesome!'
this.awesomeFunc = function(text) {
console.log(text + ' is awesome!')
}
}
var awesomeObject = new AwesomeClass()
function middleware(func) {
oldFunc = func.awesomeFunc
func.awesomeFunc = function(text) {
text = text + ' really'
oldFunc(text)
}
}
function anotherMiddleware(func) {
func.anotherProp = 'super duper'
}
function caller(input) {
input.awesomeFunc(input.anotherProp)
oldFunc("John");
}
middleware(awesomeObject)
anotherMiddleware(awesomeObject)
caller(awesomeObject)
The above code runs really fine.. But what I dont understand is oldFunc is a local variable of middleware function but still I am able to call it from another function i.e. caller function............. HOW!!