Avatar for user101594


Member since Jul 2019 • Last active Apr 2020
  • 2 conversations

Most recent activity

  • in JavaScript
    Avatar for user101594

    @Robin and @allObjects
    Right after you gave me your advice I went through a long patch of not having any quality thinking time, due to having two very young kids.

    But I came back to it over the weekend, reflected more on what I was doing and got pretty much to where I wanted to get to. Thanks very much for taking the time to reply - it did help. And knowing about dump() is going to be a big help going forward.

    For the record, I think that I'd been getting confused by looking at code examples which featured JSON without really clocking that they were JSON. I simplified my data to being an "object of objects", adapted my functions to not rely on indexers and now it works.

    The only thing which would have made life a bit nicer is the Object.values() method which I learnt about while reading around. I guess there isn't enough space to include everything in Espruino - shouldn't be greedy :)

  • in JavaScript
    Avatar for user101594

    I restructured my data in "days" a few times and lost understanding of what I was dealing with. I thought that it was an object as I couldn't reference its contents with an index e.g


    Firefox console says:

    TypeError: days[2] is undefined

    If it's an array after all, then I'll do some more reading about arrays. Thanks

  • in JavaScript
    Avatar for user101594

    Thank you very, very much indeed. This makes sense now, but I couldn't find any examples which illustrated it in usual places (W3, StackOverflow, etc.). Probably wasn't searching for the right terms.

  • in JavaScript
    Avatar for user101594

    I've stumbled across a problem that I can't get my head around and am not sure what to search for to learn how to resolve it. Can anyone help name a technique or method which I can read up on?

    I'm trying to access a propety of an object which changes depending on the output of a function. This is a simplified example:

    var days = {
      Monday: {hour: 6, minute: 30},
      Tuesday: {hour: 7, minute: 0},
    var today = function() {
      return "Tuesday" // simplified for this example - not sure if return is best approach

    Espruino says:

    Uncaught Error: Cannot read property 'hour' of undefined
     at line 1 col 24

    Do I need to get today to return a string instead? Any help would be much appreciated.

    This is a situation where I don't know enough to help myself :)

  • in JavaScript
    Avatar for user101594

    I'm working on a project which basically does 2 jobs, which both have different outputs depending on the current time of day:

    1. continuously watch pin for sensor data, and perform function A whenever it arrives
    2. perform function B on fixed schedule (e.g. every minute)

    I currently have a setwatch() for 1 and a function start() for 2. But both require the same function for checking the time of day and doing different things depending on it.

    What's the best way to structure this code? I'm happy doing either one, but I feel like I'm missing something in my approach to combine them.

    Sorry if I've not explained this well - thought it would be better as an abstract question, than sharing my mess of code.