Where communities thrive


  • Join over 1.5M+ people
  • Join over 100K+ communities
  • Free without limits
  • Create your own community
People
Activity
  • Aug 17 09:32
    User @bjorno43 unbanned @linkin-park
  • Jun 20 21:19
    @bjorno43 banned @shenerd140
  • Apr 25 17:13
    @mstellaluna banned @cmal
  • Jan 08 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
  • Jul 29 2018 01:00
    @bjorno43 banned @jkyereh
  • Jul 10 2018 22:09
    @bjorno43 banned @manafn
  • Jul 06 2018 15:20
    @texas2010 banned @imlegend19
  • Jul 03 2018 12:28
    @bjorno43 banned @vbvmatta
  • Jun 29 2018 13:54
    @bjorno43 banned @OGTechnoBoy
Johnny
@JohnnyBizzel
Ok where exactly? How would you fix the user pressing 2 = + 4
siliconchild
@siliconchild
2 = +4 should be treated as 2+4 right?
Johnny
@JohnnyBizzel
Yes
siliconchild
@siliconchild
equates just returns the sum, so 2 = should return 2 and then +4 should add 4 to the sum which is 2
Johnny
@JohnnyBizzel
So the user can't change their mind about the operator and there is no UI feedback on this
siliconchild
@siliconchild
I have to think through about validation and where to place it, thanks for making me think about it
Johnny
@JohnnyBizzel
I think you are right about doing it in the Event class
siliconchild
@siliconchild
2=+4 and 2+x4 is different right @JohnnyBizzel
Johnny
@JohnnyBizzel
However I went straight to the Calc class as I thought logically this is where it should be??
siliconchild
@siliconchild
2 =+4 should be 6 and 2+x4 should be 8
Johnny
@JohnnyBizzel
Yep
Also -2 - 5 = ?
NaN
Some users have a (+-) button to change the number to a negative or positive.
(I didn't)
I just detected it in my code
siliconchild
@siliconchild
yeah a seperate +/- button seems easier to implement as -2+-5 seems challenging to implement as it gets confused with -2+-5 as just -2-5, like the user changed the operator
could you tell me about object literal vs singleton class
the answers i find online are too techincal
and beyond my current understanding
also about adding comments, does my comments make sense? is this the way to explain code or can you tell me what I'm doing wrong there
Johnny
@JohnnyBizzel

could you tell me about object literal vs singleton class

I was going to ask you! If you can explain it, it means you understand it.

Comments are great. You are a rare example to many coders who don't bother commenting!!
I would say some are not necessary (for me) but if you are in the habit of writing comments, stick at it!
siliconchild
@siliconchild
Thank You, From my understanding you use classes when you need to create multiple instances of an object, when you just need one and only one instant, a object literal with methods and a class with singleton functions seem similar in utility
I'm confused which is to use when
Johnny
@JohnnyBizzel
Object literals you see everywhere these days
Very useful
Singleton class I think means you can only have once instance of that class
This is used a lot these days with modules in node for example
So you get lots of plugins for node that add functionality to your code -
These should be imported once and from then on you refer to that one instance of the module.
siliconchild
@siliconchild
@JohnnyBizzel yes classes that has one instance, i believe. these classes don;t need to be instantiated and can be used like object literals
Johnny
@JohnnyBizzel
Yes - a good technique to learn
siliconchild
@siliconchild
@JohnnyBizzel sorry i didn't understand their difference, only that node modules seem to use singletons. can you tell me what makes sense in my code, is it object literals and if so why?
Johnny
@JohnnyBizzel
Not sure. I don't see a New anywhere
As in const x = new Calc
I think this is instantiating a class
siliconchild
@siliconchild
@JohnnyBizzel Since I used static functions inside the class, There is no need to create a new instance of the object like const x = new Calc, I can just use const x = Calc.operate() like i would if i was using a simple object literal with methods
this is what confuses me
Johnny
@JohnnyBizzel
Oh ok. I have done similar in C# but not JS.
This is probably the difference then.
Not sure. I would have to read up on it more.
Thanks :)
siliconchild
@siliconchild
From reading online I sort of think that object literals and singletons classes are essentially the same thing, just different ways of writing the same. But I cold be entirely wrong
Johnny
@JohnnyBizzel
@siliconchild Could be.
Aditya
@ezioda004
@siliconchild Semantically Object literals and Classes are different thing. Classes are literal syntactical sugar for:
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");
  }
}
As I can see you have constructor() function but you arent instantiating the class, so shouldnt you use static class field instead?
A recent JS proposal is adding 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;
    }
 ...
siliconchild
@siliconchild
I didn't knew about static variables, makes sense . Thank you