In console, when I define a constructor function and then add a property to it after the fact, running console.log(myConstructor)
does not disclose that property. However, when I run console.dir(myConstructor)
I can now see the property I added, as well as many others. What is the difference between the properties I can see with console.log
and the ones I can't? Are there specific terms or vocabulary one can use to distinguish between those two types of properties?
function myConstructor(){
this.sayHi = function(){
console.log("hey")
}
}
myConstructor.boop = "thing"
console.log(myConstructor)
=> ƒ myConstructor(){
this.sayHi = function(){
console.log("hey")
}
}
console.dir(myConstructor)
=> ƒ myConstructor()
boop : "thing"
arguments:null
caller:null
length:0
name:"myConstructor"
prototype:{constructor: ƒ}
__proto__:ƒ ()
[[FunctionLocation]]:VM123:1
[[Scopes]]:Scopes[1]
Please find the reference to console.dir to understand why that is happening: https://developer.mozilla.org/en-US/docs/Web/API/Console/dir
console.log logs whatever you throw there (in your case it will log the function) and dir logs the properties of the object; from the docs: