function Car (name){
this.name = name
}
Car.prototype.sound = function(){
console.log("vroom");
}
// class syntax
class Car {
constructor(name){
this.name = name;
}
sound(){
console.log("vroom");
}
}
constructor()
function but you arent instantiating the class, so shouldnt you use static
class field instead?
static
fields to the class, I think it'd be better for your use case:class Calc {
static sum;
static operatorMemory;
static reset() {
Calc.sum = undefined;
Calc.operatorMemory = undefined;
}
...
Can you also tell me the difference between using
class Calc {
static sum;
static operatorMemory;
static reset() {
Calc.sum = undefined;
Calc.operatorMemory = undefined;
}
}
and using a object like this
const calc = {
sum,
operatorMemory,
reset: function reset() {
this.sum = undefined;
this.operatorMemory = undefined;
}
}
I am confused when to use which
new
one, you are using class/static methods, whereas when you create a new instance you have access to its prototype/instance methods.
I have used this function to initiate the app
class Event{
........
........
static init() {
document.addEventListener("DOMContentLoaded", function () {
Event.captureInput();
});
}
Event.init();
on my local server this doesn't fire and i have to manually run Event.captureInput() in my console to get it woring, on codepen though it works fine
Hello everyone,
in a responsive layout which is arranged by using flexbox, how would I achieve an element to span 100% width, like in the following example?
I want my red background of the ul to span across the whole length in responsive mode.
(Math.pow(10,16) - 1); // 10000000000000000