Where communities thrive


  • Join over 1.5M+ people
  • Join over 100K+ communities
  • Free without limits
  • Create your own community
People
Activity
  • Jun 19 2020 20:09
    @krisb1220 banned @Gastony
  • May 14 2020 22:39
    @bjorno43 banned @minitechtips_twitter
  • May 14 2020 22:38
    @bjorno43 banned @real-action
  • Feb 01 2020 00:27
    @bjorno43 banned @Ndoua
  • Jan 07 2020 03:10
    @bjorno43 banned @doctor-sam
  • Aug 17 2019 09:32
    User @bjorno43 unbanned @linkin-park
  • Jun 20 2019 21:19
    @bjorno43 banned @shenerd140
  • Apr 25 2019 17:13
    @mstellaluna banned @cmal
  • Jan 08 2019 22:05
    @mstellaluna banned @dertiuss323
  • Nov 07 2018 04:42
    User @texas2010 unbanned @ows-ali
  • Nov 02 2018 16:25
    @texas2010 banned @ows-ali
  • Oct 12 2018 05:50
    @bjorno43 banned @NACH74
  • Oct 05 2018 23:02
    @mstellaluna banned @JomoPipi
  • Sep 16 2018 12:21
    @bjorno43 banned @yash-kedia
  • Sep 16 2018 12:16
    @bjorno43 banned @vnikifirov
  • Sep 05 2018 08:12
    User @bjorno43 unbanned @androuino
  • Sep 05 2018 07:38
    @bjorno43 banned @androuino
  • Aug 23 2018 16:57
    User @bjorno43 unbanned @rahuldkjain
  • Aug 23 2018 16:23
    @bjorno43 banned @rahuldkjain
  • Jul 29 2018 14:13
    User @bjorno43 unbanned @jkyereh
Aditya
@ezioda004
Since its a stage 3 proposal and not a standard feature just yet.
siliconchild
@siliconchild
oh so i cannot use static sum just yet without relying on babel?
Aditya
@ezioda004
Sadly no, but its again just syntactic sugar for:
class Calc {
}
Calc.sum;
Calc.operatorMemory;
So you can still use this
siliconchild
@siliconchild
so i have to define the variables outside the class?
Aditya
@ezioda004
Correct.
siliconchild
@siliconchild
what i did only makes sense if need multiple instances of those variables? right?
Aditya
@ezioda004
You mean the constructor() method?
siliconchild
@siliconchild
yeah
Aditya
@ezioda004
Yeah that method is only executed if you instantiate a class like const x = new Calc()
Otherwise its not executed so whatevers inside of it isnt ran either.
If you're interested this is how transpilation works
BTW I like the minimalist design of your calc, goodjob!
siliconchild
@siliconchild

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

Aditya
@ezioda004
So former one is more classical OOP that you learn in Java, C++, Python. Latter one is more prototypical inheritance, ie more javascript-y
Honestly, this is more subjective question - many will tell you to use the first one, others will tell you to use the second one as there is no correct answer and both are different design pattern
I personally like to use the first one since it feels more ergonomic to me.
siliconchild
@siliconchild
yeah the first on looks cleaner. So, under the hood it's just the same?
just a different way of writing things without any application difference?
Aditya
@ezioda004
Both are different under the hood too, class are synonym with functions in JS - but the examples solves the same problem, just different approaches
siliconchild
@siliconchild
ok thanks for clearing that up.
the first one with the class is called a singleton and the second one is called an object literal, right?
When i searched online, I came across these terms
just wanted to make sure my understanding of the terms are correct
Aditya
@ezioda004
Its not singleton, since singleton classes are the ones which have only 1 instance, your class doesnt have any instance...but singleton concept doesnt fit with JS. In classical OOP's class is a blueprint, but in JS - classes are an object themselves so its kinda misleading
siliconchild
@siliconchild
Okay so in JS since the class is already an object you can use it as it is, without making an instance of it.
Is that what happens with Classes with static variables and functions
Aditya
@ezioda004
Yes, classes are functions, functions are objects with [[Callable]] internal property.
ehutchllew
@ehutchllew
@siliconchild So you're essentially starting to dive into the realm of JS Prototyping. And when you "use" the class directly without creating a new one, you are using class/static methods, whereas when you create a new instance you have access to its prototype/instance methods.
like Array.isArray() vs Array.prototype.find()
siliconchild
@siliconchild
I have this strange behaviour where my code works fine on local server and it's buggy on codepen.
can some one point out possible causes
siliconchild
@siliconchild
Functions such as being able to do 2+4=(6 )*2 and get 12. ie to use equate in between works on my local server but not on codepen
another functionality is when user does 2+4=(6 ) and then enters a new number the calculator resets itself, this too works on local server and not on codepen

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

siliconchild
@siliconchild
Can someone guide me to possible causes?
siliconchild
@siliconchild
The codepen bug is resolved, I still run into the addEventListener not loading Event.captureEvent Error
siliconchild
@siliconchild
in JS is there a way to produce the number 9999999999999999 with an expression like (9..16)
siliconchild
@siliconchild
for now i managed with (Math.pow(10,16) - 1)
Precious Adeyinka
@precious-adeyinka
Hello good morning from here.
Christopher
@bradley1492

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.

https://codepen.io/bradley1492/pen/OrLvjo?editors=1100

Stevegolden12
@Stevegolden12
@bradley1492 The reason why the ul is not expanding is that the nav containing it was at a smaller width. So: nav{width:100%}
Aditya
@ezioda004
@siliconchild I dont think that'd work
The max value before JS numbers start overflowing is:
Number.MAX_SAFE_INTEGER; // 9007199254740991
(Math.pow(10,16) - 1); // 10000000000000000
One way to resolve this would be using string instead of a number.
Christopher
@bradley1492
@Stevegolden12 Many thanks for the nav tip :)
Jim Montgomery
@jimmielemontgomery
@bradtaniguchi I was hoping the fetches would internally all be handled via a single http request (in the case of all idempotent/non-POST-methods). It appears I need to abstract this away myself as it's not internal to the browser/spec/etc? The previous sample was: Promise.all[fetch('/'),fetch('/'),fetch('/')]).then(console.log) which again I was expecting as a single-request
Brad
@bradtaniguchi
@jimmielemontgomery Not sure if you mean tto tag me, but there is no such thing as a "single-HTTP-request" for multiple fetches. Each fetch = a request. The Promise.all is used to have a callback execute once ALL of the fetchs are resolved (or one errors out)
sorry not callback, but rather promise is resolved/rejected
But that is a layer of abstraction above how the actual http-requests are sent/build
Jim Montgomery
@jimmielemontgomery
Yes thanks Brad @bradtaniguchi, I was responding to your response of several days ago and see the 1-1 relationship now.