I need to now whats the meaning of an expression like this in Javascript
static get is() { return "custom-element"; }
I guess that static
can have a behaviour similar to Java or C++ but I need more information about these syntax.
I need to now whats the meaning of an expression like this in Javascript
static get is() { return "custom-element"; }
I guess that static
can have a behaviour similar to Java or C++ but I need more information about these syntax.
You are correct. They are pretty much close to any other object oriented programming languages like C++ and Java
Everything is documented. That is a static method you are looking at and the get is a getter
for the property or the Object you want to get.
If you look at explore static
static methods. Static properties (or class properties) are properties of Foo itself. If you prefix a method definition with static, you create a class method:
> typeof Foo.staticMethod
'function'
> Foo.staticMethod()
'classy'
And static property:
I can't think a great example than given in docs on top of my head right now. Here i am pasting essential part.
class Point {
constructor(x, y) {
this.x = x;
this.y = y;
}
}
Point.ZERO = new Point(0, 0);
You could use Object.defineProperty() to create a read-only property, but I like the simplicity of an assignment.
Second, you can create a static getter:
class Point {
constructor(x, y) {
this.x = x;
this.y = y;
}
static get ZERO() {
return new Point(0, 0);
}
}
In both cases, you get a property Point.ZERO that you can read. In the first case, the same instance is returned every time. In the second case, a new instance is returned every time.