I was interested in ways you could call a function.
For example, the native function scrollIntoView()
can be called like el.scrollIntoView()
with el
being a parameter in the function.
I want to know if I could create something similar.
Is this behavior reserved for native functions, or could you code it yourself?
Thank you!
It's simply an object you access property of, it's the most basic syntax
const el = {
param: "My function trigger",
myFunction() {
console.log(this.param);
}
}
el.myFunction();
The created elements you talk about are all instances of classes that inherit the base class Element. As such they share same parts of the interfaces and they have similar callable methods, ex:
class el {
constructor(param){
this.param=param;
}
myFunction() {
console.log(this.param);
}
}
const el1 = new el("My function param 1");
const el2 = new el("My function param 2");
el1.myFunction();
el2.myFunction();