How does the functions differ from objects in Javascript? -
this question has answer here:
- set document.getelementbyid variable 5 answers
i have habit of using function id(_id) { return document.getelementbyid(_id); }
lessen work of typing on , over.
sidenote:
jquery becomes heavy small tasks , projects
as learnt javascript more came know can pass around functions objects can do
var id = document.getelementbyid;
it seems both exact same thing. however, not expert in javascript, there difference internally? , preferred way of using?
yes, context is:
const log = console.log; log("test");
the upper wont work because context changed, , log must called on console object, not on window ( aka without context). however, there easy workarounds:
const log = console.log.bind(console);
or use functions, example arrow ones:
const log = (...args) => console.log(...args);
Comments
Post a Comment