I happened to see this code in the Vue 2's document, this question is not about Vue, but Javascript syntax specifically. I hope there's someone out there can give me a clear explanation that I've been looking for. Here it goes, This piece of code on Vue's document:
var s = JSON.stringfy
someValue = s(arrayToStringfy)
If I understand it correctly, they are storing a reference of JSON.stringfy
function to the variable s
. So I'm trying to do the same thing with other function, it works as expected, but not until I try with document.getElementById
. This piece of code below just doesn't work:
var doc = document.getElementById
doc('main') //Uncaught TypeError: Illegal invocation
at <anonymous>
I did try to console the doc
and it indeed said that doc
is a function
console.log(typeof doc) // "function"
Is there something going on here that I didn't know about? Just want to make sure that you should not focus on the id
'main' as I'm a hundred percent sure there is a div
with the id
'main'