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
Anton
@yozhikvtumane
@KUBIX90 forget this minutes: 5 , count seconds and display them in needed format with Date()
Mark Kubik
@KUBIX90
@yozhikvtumane Yeah so i was going to change that to baseDate: new Date(0, 0, 0, 0, 5, 0); and then minutes: data.baseDate.getMinutes()
minus the semi colon typo
although the above doesnt seem to work for some reason
says data is not defined
which is odd
Mark Kubik
@KUBIX90
I satill can; solve this, why would it be coming back as undefined?
i still
Anton
@yozhikvtumane
@KUBIX90 somthing like this let t = { a: ()=> b = new Date(1970,0,1) } t.a()
Mark Kubik
@KUBIX90
is the new Date object not allowed tin another object or something?
Just don't why it has to be outside my data object
Christopher McCormack
@cmccormack
@KUBIX90 you can't reference a property within an object if it isn't yet defined
Mark Kubik
@KUBIX90
let data = {
baseDate: new Date (0,0,0,0,5),
    minutes: data.baseDate.getMinutes(),
    seconds: 0,
}
@cmccormack I just don't understand why data.minutes does not work in this instance
I would have thought the first line has been defined
same way the seconds property has been defined as 0 and can be logged fine
Christopher McCormack
@cmccormack
@KUBIX90 baseDate doesn't exist to be referenced until after the object has been created, so you cannot reference it
Mark Kubik
@KUBIX90
@cmccormack In that case I don't get why the seconds property works OK
Christopher McCormack
@cmccormack
seconds is simply another property you are adding to data it is not referencing anything, just being assigned a value of 0
Mark Kubik
@KUBIX90
so base date references an object that hasn't been created yet hence why it is undefined?
Christopher McCormack
@cmccormack
@KUBIX90 exactly
Mark Kubik
@KUBIX90
OK I see that makes sense, so how would i go about being able to reference it? Does it need to be defined outside of this data object? How would I then be able to use the it within the data object?
If that makes sense
Christopher McCormack
@cmccormack
@KUBIX90 yup just create a baseDate variable above your object declaration
Mark Kubik
@KUBIX90
I suppose the only reason i haven done that is because i don't want to define anything globally, or would thats be OK in this instance
Christopher McCormack
@cmccormack

or you can create the same new Date object you did in baseDate for `minutes:

let data = {
    baseDate: new Date (0,0,0,0,5),
    minutes: new Date(0,0,0,0,5).getMinutes(),
    seconds: 0,
}

not 100% sure that will work but you can try it

Aditya
@ezioda004
@KUBIX90 You could do this too:
let data = {
  baseDate: new Date (0,0,0,0,5),
  minutes(){
    return data.baseDate.getMinutes();
  },
  seconds: 0,
}
Christopher McCormack
@cmccormack
@KUBIX90 it's up to you, you can create a global object that contains properties if you want, then you're only adding one object to the global object
Mark Kubik
@KUBIX90
@ezioda004 Thats interesting, that minutes property is just an anonymous function correct?
I have to go now, but thanks for your help both, given me a few things to think about @ezioda004 @cmccormack
Aditya
@ezioda004
@KUBIX90 Yes - its indeed an anonymous function; its syntactic sugar for:
minutes: function(){
  return
}
Christopher McCormack
@cmccormack
@ezioda004 solution is better, depending on what your doing of course
Aditya
@ezioda004
I'd also use this to refer data object, I think thats more ergonomic.
Christopher McCormack
@cmccormack
but you must call data using new as well
Aditya
@ezioda004
@cmccormack Why?
Christopher McCormack
@cmccormack
this isn't returned if you don't use new
I think
Aditya
@ezioda004
I mean like:
let data = {
  baseDate: new Date (0,0,0,0,5),
  minutes(){
    return this.baseDate.getMinutes();
  },
  seconds: 0,
}
Christopher McCormack
@cmccormack
function date(){
  this.time = Date.now()
}

console.log(new date().time) // Logs time
console.log(date().time) // Throws TypeError: Cannot read property 'time' of undefined
does an object have a this?
Aditya
@ezioda004
Ofcourse it does :D
Christopher McCormack
@cmccormack
ugh it all gets mixed up in my head haha
Aditya
@ezioda004
Are you ready to have your mind blown? Objects also have super
Christopher McCormack
@cmccormack
that's right it has a this but if you're instantiating a class you need to use new
Aditya
@ezioda004
Hes not using class tho but yeah you need new with function constructor
@cmccormack
var obj1 = {
  method1() {
    console.log('method 1');
  }
}

var obj2 = {
  method2() {
   super.method1();
  }
}

Object.setPrototypeOf(obj2, obj1);
obj2.method2(); // method 1
Christopher McCormack
@cmccormack
@ezioda004 I think I remember that from JS the good parts, but I never seem to need to use any of that stuff lol
Aditya
@ezioda004
Lol yeah same, its just good to know that it can be used; for academic purpose :D
Christopher McCormack
@cmccormack
We need something akin to a word-a-day calendar to remind us of the more esoteric parts of programming lol
Aditya
@ezioda004
Thats a cool idea! Like a daily TIL for programming