Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. The Lounge
  3. Javascript

Javascript

Scheduled Pinned Locked Moved The Lounge
javascriptcsharppythonvisual-studiolinq
29 Posts 17 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • M Marc Clifton

    So Javascript is actually pretty cool. Queue "Join the dark side, Marc". Working with arrays and dictionaries is really easy, particularly with functions like map, reduce, and Object.entries. I still have to give our own [Sander's Javascript LINQ](https://github.com/SanderRossel/arrgh.js) a whirl, but for now I haven't needed it yet. set/get is incredibly useful. this and bind is someone's idea of hell, but once you figure it out, it works. Being able to pass functions as parameters is incredibly useful, and creating partial functions is also really useful.

    partialOnDrag(anchors, anchorElement, onDrag) {
        return (function (anchors, anchorElement, onDrag) {
            return function (dx, dy) { onDrag(anchors, anchorElement, dx, dy); }
        })(anchors, anchorElement, onDrag);
    }
    

    It let's you get away with murder. Good grief, I can create/assign a class' function to a completely different function with "=". Well, functions are functions! It drives me nuts (as with any scripted language) to have to figure out if I wrote the code correctly by actually running it. Things like typos, forgotten this. and other stupid mistakes a compiler would catch. I need to explore some Lint apps. Dealing with attributes, which are strings, when you want them as numbers to do math on. Ugh. And crazy workarounds, like +"1" is actually the number 1. Classes are cool, but then there's the "class-like" hack of creating an object with key-value pairs where the key is the function "name" and the value is the function. Is that old school? var vs. let. Riiight. That was useful to know about. I haven't even touched what looks like the cesspool of prototype. Probably something I should learn. But overall, I'm actually starting to get comfortable with what I'm doing. Meaning that I'm actually starting to spend more time debugging my code logic than debugging my stupid syntax mistakes or quirky Javascript behaviors. Anyways, just thought you'd like all like to know what I've been learning writing my next article on dynamic SVG and creating a bare-bones diagramming app. :laugh:

    Latest Article - Contextual Data Explorer Learning to code with python is like learning to swim with those little arm floaties. It gives you undeserved confidence and will eventually dr

    K Offline
    K Offline
    kmoorevs
    wrote on last edited by
    #7

    Great topic! :thumbsup: The tools available these days for debugging are awesome compared to around 20 years ago when I started learning/using javascript. Alert() was my only friend! :laugh: Some of those earliest javascript functions I wrote have survived mostly unchanged. That said, I was frustrated the other day at the lack of built-in date/time formatting...you want a nice looking date, you have to roll your own function! Yeah, it has it's quirks, but once you understand them, it's amazing what you can do with javascript/css. :) It's also amazing to me how many javascript developers don't error-proof their code, apparently being content to let the browser eat the exceptions...except that some clients (don't ask me why) have enabled debugging and get to see all those nasty little undefined and NaN errors, and even get the opportunity to debug it. :omg: :confused: Yeah, this really confuses the end users, 'cause they're really not sure what to do as this is not covered in the product documentation...so they call, or send a screenshot...and I think to myself: a: why do they have debugging enabled in the first place b: the question is quite clear to me...to debug or not to debug (internal voice sarcastically, 'are you a f*%king programmer? :mad: Of course you dumb twit, you should click the Cancel button!)' What's painful is setting up for debugging, then using that browser in the real world. Cancel...Cancel...Cancel...Cancel...∞ :laugh:

    "Go forth into the source" - Neal Morse

    K 1 Reply Last reply
    0
    • M Marc Clifton

      So Javascript is actually pretty cool. Queue "Join the dark side, Marc". Working with arrays and dictionaries is really easy, particularly with functions like map, reduce, and Object.entries. I still have to give our own [Sander's Javascript LINQ](https://github.com/SanderRossel/arrgh.js) a whirl, but for now I haven't needed it yet. set/get is incredibly useful. this and bind is someone's idea of hell, but once you figure it out, it works. Being able to pass functions as parameters is incredibly useful, and creating partial functions is also really useful.

      partialOnDrag(anchors, anchorElement, onDrag) {
          return (function (anchors, anchorElement, onDrag) {
              return function (dx, dy) { onDrag(anchors, anchorElement, dx, dy); }
          })(anchors, anchorElement, onDrag);
      }
      

      It let's you get away with murder. Good grief, I can create/assign a class' function to a completely different function with "=". Well, functions are functions! It drives me nuts (as with any scripted language) to have to figure out if I wrote the code correctly by actually running it. Things like typos, forgotten this. and other stupid mistakes a compiler would catch. I need to explore some Lint apps. Dealing with attributes, which are strings, when you want them as numbers to do math on. Ugh. And crazy workarounds, like +"1" is actually the number 1. Classes are cool, but then there's the "class-like" hack of creating an object with key-value pairs where the key is the function "name" and the value is the function. Is that old school? var vs. let. Riiight. That was useful to know about. I haven't even touched what looks like the cesspool of prototype. Probably something I should learn. But overall, I'm actually starting to get comfortable with what I'm doing. Meaning that I'm actually starting to spend more time debugging my code logic than debugging my stupid syntax mistakes or quirky Javascript behaviors. Anyways, just thought you'd like all like to know what I've been learning writing my next article on dynamic SVG and creating a bare-bones diagramming app. :laugh:

      Latest Article - Contextual Data Explorer Learning to code with python is like learning to swim with those little arm floaties. It gives you undeserved confidence and will eventually dr

      J Offline
      J Offline
      Jon McKee
      wrote on last edited by
      #8

      Marc Clifton wrote:

      this and bind is someone's idea of hell, but once you figure it out, it works.

      This perfectly sums up how I feel about this as well.

      Marc Clifton wrote:

      I haven't even touched what looks like the cesspool of prototype. Probably something I should learn.

      It's really not that bad :thumbsup:

      Mozilla Developer Network[^]:

      When it comes to inheritance, JavaScript only has one construct: objects. Each object has a private property which holds a link to another object called its prototype. That prototype object has a prototype of its own, and so on until an object is reached with null as its prototype. By definition, null has no prototype, and acts as the final link in this prototype chain.

      1 Reply Last reply
      0
      • M Marc Clifton

        So Javascript is actually pretty cool. Queue "Join the dark side, Marc". Working with arrays and dictionaries is really easy, particularly with functions like map, reduce, and Object.entries. I still have to give our own [Sander's Javascript LINQ](https://github.com/SanderRossel/arrgh.js) a whirl, but for now I haven't needed it yet. set/get is incredibly useful. this and bind is someone's idea of hell, but once you figure it out, it works. Being able to pass functions as parameters is incredibly useful, and creating partial functions is also really useful.

        partialOnDrag(anchors, anchorElement, onDrag) {
            return (function (anchors, anchorElement, onDrag) {
                return function (dx, dy) { onDrag(anchors, anchorElement, dx, dy); }
            })(anchors, anchorElement, onDrag);
        }
        

        It let's you get away with murder. Good grief, I can create/assign a class' function to a completely different function with "=". Well, functions are functions! It drives me nuts (as with any scripted language) to have to figure out if I wrote the code correctly by actually running it. Things like typos, forgotten this. and other stupid mistakes a compiler would catch. I need to explore some Lint apps. Dealing with attributes, which are strings, when you want them as numbers to do math on. Ugh. And crazy workarounds, like +"1" is actually the number 1. Classes are cool, but then there's the "class-like" hack of creating an object with key-value pairs where the key is the function "name" and the value is the function. Is that old school? var vs. let. Riiight. That was useful to know about. I haven't even touched what looks like the cesspool of prototype. Probably something I should learn. But overall, I'm actually starting to get comfortable with what I'm doing. Meaning that I'm actually starting to spend more time debugging my code logic than debugging my stupid syntax mistakes or quirky Javascript behaviors. Anyways, just thought you'd like all like to know what I've been learning writing my next article on dynamic SVG and creating a bare-bones diagramming app. :laugh:

        Latest Article - Contextual Data Explorer Learning to code with python is like learning to swim with those little arm floaties. It gives you undeserved confidence and will eventually dr

        J Offline
        J Offline
        Jacquers
        wrote on last edited by
        #9

        I think you might like Typescript and visual studio code :)

        1 Reply Last reply
        0
        • M Marc Clifton

          So Javascript is actually pretty cool. Queue "Join the dark side, Marc". Working with arrays and dictionaries is really easy, particularly with functions like map, reduce, and Object.entries. I still have to give our own [Sander's Javascript LINQ](https://github.com/SanderRossel/arrgh.js) a whirl, but for now I haven't needed it yet. set/get is incredibly useful. this and bind is someone's idea of hell, but once you figure it out, it works. Being able to pass functions as parameters is incredibly useful, and creating partial functions is also really useful.

          partialOnDrag(anchors, anchorElement, onDrag) {
              return (function (anchors, anchorElement, onDrag) {
                  return function (dx, dy) { onDrag(anchors, anchorElement, dx, dy); }
              })(anchors, anchorElement, onDrag);
          }
          

          It let's you get away with murder. Good grief, I can create/assign a class' function to a completely different function with "=". Well, functions are functions! It drives me nuts (as with any scripted language) to have to figure out if I wrote the code correctly by actually running it. Things like typos, forgotten this. and other stupid mistakes a compiler would catch. I need to explore some Lint apps. Dealing with attributes, which are strings, when you want them as numbers to do math on. Ugh. And crazy workarounds, like +"1" is actually the number 1. Classes are cool, but then there's the "class-like" hack of creating an object with key-value pairs where the key is the function "name" and the value is the function. Is that old school? var vs. let. Riiight. That was useful to know about. I haven't even touched what looks like the cesspool of prototype. Probably something I should learn. But overall, I'm actually starting to get comfortable with what I'm doing. Meaning that I'm actually starting to spend more time debugging my code logic than debugging my stupid syntax mistakes or quirky Javascript behaviors. Anyways, just thought you'd like all like to know what I've been learning writing my next article on dynamic SVG and creating a bare-bones diagramming app. :laugh:

          Latest Article - Contextual Data Explorer Learning to code with python is like learning to swim with those little arm floaties. It gives you undeserved confidence and will eventually dr

          S Offline
          S Offline
          Stuart Dootson
          wrote on last edited by
          #10

          The feeling I always get with Javascript is that feeling of insecurity... 'I presumed that parameter will be a number and it always will be....won't it?'. Maybe I like my static typing 'crutch' too much, or maybe it's because I like the idea of domain modelling with types, but things like TypeScript and PureScript appeal to me as Javascript front-ends more than Javascript itself...

          Java, Basic, who cares - it's all a bunch of tree-hugging hippy cr*p

          1 Reply Last reply
          0
          • R Ryan Peden

            JavaScript can be pretty neat, but with lots of rough edges. > Classes are cool, but then there's the "class-like" hack of creating an object with key-value pairs where the key is the function "name" and the value is the function. Is that old school? That's one old school way to do it, but it's not quite equivalent. Creating an object where the function names are the keys in the key value pairs is equivalent to creating a class with nothing but static methods in C#. Of course, using ES2017+ syntax, you can just create static functions in your JS class. So something like this:

            const AnObject {
            aFunction: function() {
            console.log("hi");
            }
            }

            ends up being exactly the same as

            class AClass {
            static aFunction() {
            console.log("hi");
            }
            }

            The old school equivalent to a class declaration would look like this:

            function MyClass(abc) {
            this.abc = abc;
            }

            MyClass.prototype.printAbc = function() {
            console.log(abc);
            }

            Which ends up doing the same as:

            class MyClass {
            constructor(abc) {
            this.abc = abc;
            }

            printAbc() {
            console.log(abc);
            }
            }

            In either case, the following code will have exactly the same result:

            let something = new MyClass();
            something.printAbc();

            The class syntax is mostly just syntactic sugar; at the end of the day, the JavaScript runtime ends up doing what's shown in the first example, i.e. creating a constructor function and then adding the class's methods to the constructor function's prototype. Understanding protytypes is pretty useful. Understanding them means you understand how the entire JS class system works. And fortunately, protytypes aren't that big a cesspool if you've got a good teacher. Probably the best resource on the topic (even though it's quite old now) is JavaScript: The Good Parts. It's an easy read, and enjoyable because the author is a bit of a grump and isn't shy about noting the bad parts of JS along with the good ones. The book predates some of the newer syntax, like let, const, and even class. But if you keep in mind that the class syntax is really just using prototypes under the hood, then almost everything in the book will be very relevant to what you're doing now. One thing the book won't cover is Promises, along with how the new async/await that simplifies using Promises. Its very, very similar to how the async/await syntax in C# makes it easy to work with Tasks.

            M Offline
            M Offline
            Marc Clifton
            wrote on last edited by
            #11

            That was a fantastic write-up!

            Latest Article - Contextual Data Explorer Learning to code with python is like learning to swim with those little arm floaties. It gives you undeserved confidence and will eventually drown you. - DangerBunny Artificial intelligence is the only remedy for natural stupidity. - CDP1802

            1 Reply Last reply
            0
            • M Marc Clifton

              So Javascript is actually pretty cool. Queue "Join the dark side, Marc". Working with arrays and dictionaries is really easy, particularly with functions like map, reduce, and Object.entries. I still have to give our own [Sander's Javascript LINQ](https://github.com/SanderRossel/arrgh.js) a whirl, but for now I haven't needed it yet. set/get is incredibly useful. this and bind is someone's idea of hell, but once you figure it out, it works. Being able to pass functions as parameters is incredibly useful, and creating partial functions is also really useful.

              partialOnDrag(anchors, anchorElement, onDrag) {
                  return (function (anchors, anchorElement, onDrag) {
                      return function (dx, dy) { onDrag(anchors, anchorElement, dx, dy); }
                  })(anchors, anchorElement, onDrag);
              }
              

              It let's you get away with murder. Good grief, I can create/assign a class' function to a completely different function with "=". Well, functions are functions! It drives me nuts (as with any scripted language) to have to figure out if I wrote the code correctly by actually running it. Things like typos, forgotten this. and other stupid mistakes a compiler would catch. I need to explore some Lint apps. Dealing with attributes, which are strings, when you want them as numbers to do math on. Ugh. And crazy workarounds, like +"1" is actually the number 1. Classes are cool, but then there's the "class-like" hack of creating an object with key-value pairs where the key is the function "name" and the value is the function. Is that old school? var vs. let. Riiight. That was useful to know about. I haven't even touched what looks like the cesspool of prototype. Probably something I should learn. But overall, I'm actually starting to get comfortable with what I'm doing. Meaning that I'm actually starting to spend more time debugging my code logic than debugging my stupid syntax mistakes or quirky Javascript behaviors. Anyways, just thought you'd like all like to know what I've been learning writing my next article on dynamic SVG and creating a bare-bones diagramming app. :laugh:

              Latest Article - Contextual Data Explorer Learning to code with python is like learning to swim with those little arm floaties. It gives you undeserved confidence and will eventually dr

              Sander RosselS Offline
              Sander RosselS Offline
              Sander Rossel
              wrote on last edited by
              #12

              Marc Clifton wrote:

              I still have to give our own Sander's Javascript LINQ a whirl

              Sounds like you should read Apply, Call and Bind on JavaScript functions[^] and Prototype in JavaScript[^] by that same Sander. This Sander guy really sounds like a smart dude! :laugh:

              Marc Clifton wrote:

              Working with arrays and dictionaries is really easy

              How is

              var array = [2, 5, 9];
              var index = array.indexOf(5);
              if (index > -1) {
              array.splice(index, 1);
              }

              easy!? :wtf: Can you even tell what it does? It simply removes 5 from the array and I had to Google this (again)... The best part is that you might need a polyfill for indexOf if you need to support older browsers :laugh: The equivalent in arrgh.js:

              var l = new List([2, 5, 9]);
              l.remove(5);

              Works in older browsers too, no polyfills necessary :D And then, of course, there's the complete LINQ library that JavaScript lacks ;) I'll admit that you usually don't need LINQ in your browser and getting arrgh just for remove is a bit overkill :laugh: Did I mention Node.js is also supported...? :D

              Best, Sander Continuous Integration, Delivery, and Deployment arrgh.js - Bringing LINQ to JavaScript Object-Oriented Programming in C# Succinctly

              L M 2 Replies Last reply
              0
              • R Ryan Peden

                JavaScript can be pretty neat, but with lots of rough edges. > Classes are cool, but then there's the "class-like" hack of creating an object with key-value pairs where the key is the function "name" and the value is the function. Is that old school? That's one old school way to do it, but it's not quite equivalent. Creating an object where the function names are the keys in the key value pairs is equivalent to creating a class with nothing but static methods in C#. Of course, using ES2017+ syntax, you can just create static functions in your JS class. So something like this:

                const AnObject {
                aFunction: function() {
                console.log("hi");
                }
                }

                ends up being exactly the same as

                class AClass {
                static aFunction() {
                console.log("hi");
                }
                }

                The old school equivalent to a class declaration would look like this:

                function MyClass(abc) {
                this.abc = abc;
                }

                MyClass.prototype.printAbc = function() {
                console.log(abc);
                }

                Which ends up doing the same as:

                class MyClass {
                constructor(abc) {
                this.abc = abc;
                }

                printAbc() {
                console.log(abc);
                }
                }

                In either case, the following code will have exactly the same result:

                let something = new MyClass();
                something.printAbc();

                The class syntax is mostly just syntactic sugar; at the end of the day, the JavaScript runtime ends up doing what's shown in the first example, i.e. creating a constructor function and then adding the class's methods to the constructor function's prototype. Understanding protytypes is pretty useful. Understanding them means you understand how the entire JS class system works. And fortunately, protytypes aren't that big a cesspool if you've got a good teacher. Probably the best resource on the topic (even though it's quite old now) is JavaScript: The Good Parts. It's an easy read, and enjoyable because the author is a bit of a grump and isn't shy about noting the bad parts of JS along with the good ones. The book predates some of the newer syntax, like let, const, and even class. But if you keep in mind that the class syntax is really just using prototypes under the hood, then almost everything in the book will be very relevant to what you're doing now. One thing the book won't cover is Promises, along with how the new async/await that simplifies using Promises. Its very, very similar to how the async/await syntax in C# makes it easy to work with Tasks.

                D Offline
                D Offline
                ddt_tdd
                wrote on last edited by
                #13

                Next to the book of Douglas Crockford, I would also recommend the videos on youtube "Crockford on Javascript". It is fun to watch and gives a good insight where Javascript comes from. If on the otherhand you want a compiler, please do evaluate typescript. It is a language which is strongly typed and compiles to Javascript. Have fun with Javascript.

                L 1 Reply Last reply
                0
                • M Marc Clifton

                  So Javascript is actually pretty cool. Queue "Join the dark side, Marc". Working with arrays and dictionaries is really easy, particularly with functions like map, reduce, and Object.entries. I still have to give our own [Sander's Javascript LINQ](https://github.com/SanderRossel/arrgh.js) a whirl, but for now I haven't needed it yet. set/get is incredibly useful. this and bind is someone's idea of hell, but once you figure it out, it works. Being able to pass functions as parameters is incredibly useful, and creating partial functions is also really useful.

                  partialOnDrag(anchors, anchorElement, onDrag) {
                      return (function (anchors, anchorElement, onDrag) {
                          return function (dx, dy) { onDrag(anchors, anchorElement, dx, dy); }
                      })(anchors, anchorElement, onDrag);
                  }
                  

                  It let's you get away with murder. Good grief, I can create/assign a class' function to a completely different function with "=". Well, functions are functions! It drives me nuts (as with any scripted language) to have to figure out if I wrote the code correctly by actually running it. Things like typos, forgotten this. and other stupid mistakes a compiler would catch. I need to explore some Lint apps. Dealing with attributes, which are strings, when you want them as numbers to do math on. Ugh. And crazy workarounds, like +"1" is actually the number 1. Classes are cool, but then there's the "class-like" hack of creating an object with key-value pairs where the key is the function "name" and the value is the function. Is that old school? var vs. let. Riiight. That was useful to know about. I haven't even touched what looks like the cesspool of prototype. Probably something I should learn. But overall, I'm actually starting to get comfortable with what I'm doing. Meaning that I'm actually starting to spend more time debugging my code logic than debugging my stupid syntax mistakes or quirky Javascript behaviors. Anyways, just thought you'd like all like to know what I've been learning writing my next article on dynamic SVG and creating a bare-bones diagramming app. :laugh:

                  Latest Article - Contextual Data Explorer Learning to code with python is like learning to swim with those little arm floaties. It gives you undeserved confidence and will eventually dr

                  D Offline
                  D Offline
                  David Days
                  wrote on last edited by
                  #14

                  I spent about 6 months in developer hell working with JavaScript ("cool--now can you add these 5 things?") about 5 years ago, and was fairly deep into some of these concepts. Basic premise: Create a web UI to do scheduling for 5,000 workers (construction, lab, etc) that talked to the (very old) scheduling system. Kink in the process: Needed to account for all sorts of static scheduling rules (start times, end times, allowed ranges, etc) and a variable list of union rules (lots of different unions on site) to match up and validate the work, the pay rates for job type, and such. My JS coding was definitely old-school style, but prototypes were what saved the day. Date and time handling, rules, etc allowed me to push the common functions further up the chain, and going between 5 different datetime formats certainly made a difference. Same for the "rules" concept--basic rules and functions, and subclasses for specialized parameters. The whole thing was cancelled just as it was getting functional ("Oh, wait! We need to get 5 departments and 3 unions to sign off on this"), but I definitely learned a lot.

                  vuolsi così colà dove si puote ciò che si vuole, e più non dimandare --The answer to Minos and any question of "Why are we doing it this way?"

                  abmvA 1 Reply Last reply
                  0
                  • M Marc Clifton

                    So Javascript is actually pretty cool. Queue "Join the dark side, Marc". Working with arrays and dictionaries is really easy, particularly with functions like map, reduce, and Object.entries. I still have to give our own [Sander's Javascript LINQ](https://github.com/SanderRossel/arrgh.js) a whirl, but for now I haven't needed it yet. set/get is incredibly useful. this and bind is someone's idea of hell, but once you figure it out, it works. Being able to pass functions as parameters is incredibly useful, and creating partial functions is also really useful.

                    partialOnDrag(anchors, anchorElement, onDrag) {
                        return (function (anchors, anchorElement, onDrag) {
                            return function (dx, dy) { onDrag(anchors, anchorElement, dx, dy); }
                        })(anchors, anchorElement, onDrag);
                    }
                    

                    It let's you get away with murder. Good grief, I can create/assign a class' function to a completely different function with "=". Well, functions are functions! It drives me nuts (as with any scripted language) to have to figure out if I wrote the code correctly by actually running it. Things like typos, forgotten this. and other stupid mistakes a compiler would catch. I need to explore some Lint apps. Dealing with attributes, which are strings, when you want them as numbers to do math on. Ugh. And crazy workarounds, like +"1" is actually the number 1. Classes are cool, but then there's the "class-like" hack of creating an object with key-value pairs where the key is the function "name" and the value is the function. Is that old school? var vs. let. Riiight. That was useful to know about. I haven't even touched what looks like the cesspool of prototype. Probably something I should learn. But overall, I'm actually starting to get comfortable with what I'm doing. Meaning that I'm actually starting to spend more time debugging my code logic than debugging my stupid syntax mistakes or quirky Javascript behaviors. Anyways, just thought you'd like all like to know what I've been learning writing my next article on dynamic SVG and creating a bare-bones diagramming app. :laugh:

                    Latest Article - Contextual Data Explorer Learning to code with python is like learning to swim with those little arm floaties. It gives you undeserved confidence and will eventually dr

                    L Offline
                    L Offline
                    Leng Vang
                    wrote on last edited by
                    #15

                    Don't forget about the nature of JS asynchronous execution. Between the this and async is what "Gotcha" the most for new comer. Promise helps, but it is not an easy beast to tam. Once it is understood, using it is easy enough.

                    1 Reply Last reply
                    0
                    • Sander RosselS Sander Rossel

                      Marc Clifton wrote:

                      I still have to give our own Sander's Javascript LINQ a whirl

                      Sounds like you should read Apply, Call and Bind on JavaScript functions[^] and Prototype in JavaScript[^] by that same Sander. This Sander guy really sounds like a smart dude! :laugh:

                      Marc Clifton wrote:

                      Working with arrays and dictionaries is really easy

                      How is

                      var array = [2, 5, 9];
                      var index = array.indexOf(5);
                      if (index > -1) {
                      array.splice(index, 1);
                      }

                      easy!? :wtf: Can you even tell what it does? It simply removes 5 from the array and I had to Google this (again)... The best part is that you might need a polyfill for indexOf if you need to support older browsers :laugh: The equivalent in arrgh.js:

                      var l = new List([2, 5, 9]);
                      l.remove(5);

                      Works in older browsers too, no polyfills necessary :D And then, of course, there's the complete LINQ library that JavaScript lacks ;) I'll admit that you usually don't need LINQ in your browser and getting arrgh just for remove is a bit overkill :laugh: Did I mention Node.js is also supported...? :D

                      Best, Sander Continuous Integration, Delivery, and Deployment arrgh.js - Bringing LINQ to JavaScript Object-Oriented Programming in C# Succinctly

                      L Offline
                      L Offline
                      Leng Vang
                      wrote on last edited by
                      #16

                      Most modern language lack set data type. Remember old Pascal set. For example

                      if ("A" in ["A","B","C"]) then
                      .. do something.

                      I implemented it in Javascript like this.

                      function SetOf(arr) {
                      var obj = {};
                      for (var i = 0; i < arr.length; i++) {
                      obj[arr[i]] = arr[i];
                      }
                      return obj;
                      }

                      if ('A' in SetOf(['A','B','C']))
                      .. do something.

                      1 Reply Last reply
                      0
                      • D ddt_tdd

                        Next to the book of Douglas Crockford, I would also recommend the videos on youtube "Crockford on Javascript". It is fun to watch and gives a good insight where Javascript comes from. If on the otherhand you want a compiler, please do evaluate typescript. It is a language which is strongly typed and compiles to Javascript. Have fun with Javascript.

                        L Offline
                        L Offline
                        Leng Vang
                        wrote on last edited by
                        #17

                        I spend 2 years on a project using Typescript (from 0.8.xx to 2.x) along with JavaScript. At the end, on new projects, I went back to pure JS. I felt like the static type in TS is getting in the way and hinder me from what I want to do sometime. It reminded me back when I was coding using Assembler and C for kernel development. Man I feel old.

                        1 Reply Last reply
                        0
                        • abmvA abmv

                          What did you drink Mr.Clifton ?

                          Caveat Emptor. "Progress doesn't come from early risers – progress is made by lazy men looking for easier ways to do things." Lazarus Long

                          J Offline
                          J Offline
                          Jorgen Andersson
                          wrote on last edited by
                          #18

                          Koolaid?

                          Wrong is evil and must be defeated. - Jeff Ello

                          1 Reply Last reply
                          0
                          • Sander RosselS Sander Rossel

                            Marc Clifton wrote:

                            I still have to give our own Sander's Javascript LINQ a whirl

                            Sounds like you should read Apply, Call and Bind on JavaScript functions[^] and Prototype in JavaScript[^] by that same Sander. This Sander guy really sounds like a smart dude! :laugh:

                            Marc Clifton wrote:

                            Working with arrays and dictionaries is really easy

                            How is

                            var array = [2, 5, 9];
                            var index = array.indexOf(5);
                            if (index > -1) {
                            array.splice(index, 1);
                            }

                            easy!? :wtf: Can you even tell what it does? It simply removes 5 from the array and I had to Google this (again)... The best part is that you might need a polyfill for indexOf if you need to support older browsers :laugh: The equivalent in arrgh.js:

                            var l = new List([2, 5, 9]);
                            l.remove(5);

                            Works in older browsers too, no polyfills necessary :D And then, of course, there's the complete LINQ library that JavaScript lacks ;) I'll admit that you usually don't need LINQ in your browser and getting arrgh just for remove is a bit overkill :laugh: Did I mention Node.js is also supported...? :D

                            Best, Sander Continuous Integration, Delivery, and Deployment arrgh.js - Bringing LINQ to JavaScript Object-Oriented Programming in C# Succinctly

                            M Offline
                            M Offline
                            Marc Clifton
                            wrote on last edited by
                            #19

                            Sander Rossel wrote:

                            I'll admit that you usually don't need LINQ in your browser and getting arrgh just for remove is a bit overkill

                            At the moment, I'm not doing any manipulation of arrays and dictionaries other than adding items to them and iterating over them. But that might change...

                            Latest Article - Contextual Data Explorer Learning to code with python is like learning to swim with those little arm floaties. It gives you undeserved confidence and will eventually drown you. - DangerBunny Artificial intelligence is the only remedy for natural stupidity. - CDP1802

                            1 Reply Last reply
                            0
                            • R realJSOP

                              You may as well just change over to VB at this point, and be done with it. Hippie. Typeless languages are for people that lack the mental fortitude to work within strongly-typed constraints. I bet you drink coffee at Starbucks, instead of out of a boot, or a rusty can (like real men).

                              ".45 ACP - because shooting twice is just silly" - JSOP, 2010
                              -----
                              You can never have too much ammo - unless you're swimming, or on fire. - JSOP, 2010
                              -----
                              When you pry the gun from my cold dead hands, be careful - the barrel will be very hot. - JSOP, 2013

                              M Offline
                              M Offline
                              Marc Clifton
                              wrote on last edited by
                              #20

                              John Simmons / outlaw programmer wrote:

                              I bet you drink coffee at Starbucks, instead of out of a boot, or a rusty can (like real men).

                              Even worse, I drink tea, not coffee! Earl Grey at that! :laugh:

                              Latest Article - Contextual Data Explorer Learning to code with python is like learning to swim with those little arm floaties. It gives you undeserved confidence and will eventually drown you. - DangerBunny Artificial intelligence is the only remedy for natural stupidity. - CDP1802

                              R 1 Reply Last reply
                              0
                              • M Marc Clifton

                                John Simmons / outlaw programmer wrote:

                                I bet you drink coffee at Starbucks, instead of out of a boot, or a rusty can (like real men).

                                Even worse, I drink tea, not coffee! Earl Grey at that! :laugh:

                                Latest Article - Contextual Data Explorer Learning to code with python is like learning to swim with those little arm floaties. It gives you undeserved confidence and will eventually drown you. - DangerBunny Artificial intelligence is the only remedy for natural stupidity. - CDP1802

                                R Offline
                                R Offline
                                realJSOP
                                wrote on last edited by
                                #21

                                Marc Clifton wrote:

                                Even worse, I drink tea, not coffee! Earl Grey at that! :laugh:

                                BAH!

                                ".45 ACP - because shooting twice is just silly" - JSOP, 2010
                                -----
                                You can never have too much ammo - unless you're swimming, or on fire. - JSOP, 2010
                                -----
                                When you pry the gun from my cold dead hands, be careful - the barrel will be very hot. - JSOP, 2013

                                K 1 Reply Last reply
                                0
                                • R realJSOP

                                  You may as well just change over to VB at this point, and be done with it. Hippie. Typeless languages are for people that lack the mental fortitude to work within strongly-typed constraints. I bet you drink coffee at Starbucks, instead of out of a boot, or a rusty can (like real men).

                                  ".45 ACP - because shooting twice is just silly" - JSOP, 2010
                                  -----
                                  You can never have too much ammo - unless you're swimming, or on fire. - JSOP, 2010
                                  -----
                                  When you pry the gun from my cold dead hands, be careful - the barrel will be very hot. - JSOP, 2013

                                  K Offline
                                  K Offline
                                  Kirk 10389821
                                  wrote on last edited by
                                  #22

                                  LOL. That's how I feel about Garbage Collected Languages... Or, er, "Managed Code". :)

                                  1 Reply Last reply
                                  0
                                  • R realJSOP

                                    Marc Clifton wrote:

                                    Even worse, I drink tea, not coffee! Earl Grey at that! :laugh:

                                    BAH!

                                    ".45 ACP - because shooting twice is just silly" - JSOP, 2010
                                    -----
                                    You can never have too much ammo - unless you're swimming, or on fire. - JSOP, 2010
                                    -----
                                    When you pry the gun from my cold dead hands, be careful - the barrel will be very hot. - JSOP, 2013

                                    K Offline
                                    K Offline
                                    Kirk 10389821
                                    wrote on last edited by
                                    #23

                                    Let me buy you a Zima, then! LOL

                                    1 Reply Last reply
                                    0
                                    • K kmoorevs

                                      Great topic! :thumbsup: The tools available these days for debugging are awesome compared to around 20 years ago when I started learning/using javascript. Alert() was my only friend! :laugh: Some of those earliest javascript functions I wrote have survived mostly unchanged. That said, I was frustrated the other day at the lack of built-in date/time formatting...you want a nice looking date, you have to roll your own function! Yeah, it has it's quirks, but once you understand them, it's amazing what you can do with javascript/css. :) It's also amazing to me how many javascript developers don't error-proof their code, apparently being content to let the browser eat the exceptions...except that some clients (don't ask me why) have enabled debugging and get to see all those nasty little undefined and NaN errors, and even get the opportunity to debug it. :omg: :confused: Yeah, this really confuses the end users, 'cause they're really not sure what to do as this is not covered in the product documentation...so they call, or send a screenshot...and I think to myself: a: why do they have debugging enabled in the first place b: the question is quite clear to me...to debug or not to debug (internal voice sarcastically, 'are you a f*%king programmer? :mad: Of course you dumb twit, you should click the Cancel button!)' What's painful is setting up for debugging, then using that browser in the real world. Cancel...Cancel...Cancel...Cancel...∞ :laugh:

                                      "Go forth into the source" - Neal Morse

                                      K Offline
                                      K Offline
                                      Kirk 10389821
                                      wrote on last edited by
                                      #24

                                      my favorite feature is using || to override missing parameters!!! var timerSetting = paramTimer || userTimer || systemTimer || 500; the functions as parameters... That was a Throwback to CLIPPER days, where you had code snippets: {|| code} you could pass as parameters for event handlers, etc. Way cool... First language that I ever saw that in (probably because I took LISP later)... But you cdr guessed that. LOL I am HOPING that JavaScript replaces VBA as the internal scripting language of ALL programs! The more I use it, the more I like it. Kinda like JSON. The more you get used to it... the less you want to kill someone...

                                      K 1 Reply Last reply
                                      0
                                      • R Ryan Peden

                                        JavaScript can be pretty neat, but with lots of rough edges. > Classes are cool, but then there's the "class-like" hack of creating an object with key-value pairs where the key is the function "name" and the value is the function. Is that old school? That's one old school way to do it, but it's not quite equivalent. Creating an object where the function names are the keys in the key value pairs is equivalent to creating a class with nothing but static methods in C#. Of course, using ES2017+ syntax, you can just create static functions in your JS class. So something like this:

                                        const AnObject {
                                        aFunction: function() {
                                        console.log("hi");
                                        }
                                        }

                                        ends up being exactly the same as

                                        class AClass {
                                        static aFunction() {
                                        console.log("hi");
                                        }
                                        }

                                        The old school equivalent to a class declaration would look like this:

                                        function MyClass(abc) {
                                        this.abc = abc;
                                        }

                                        MyClass.prototype.printAbc = function() {
                                        console.log(abc);
                                        }

                                        Which ends up doing the same as:

                                        class MyClass {
                                        constructor(abc) {
                                        this.abc = abc;
                                        }

                                        printAbc() {
                                        console.log(abc);
                                        }
                                        }

                                        In either case, the following code will have exactly the same result:

                                        let something = new MyClass();
                                        something.printAbc();

                                        The class syntax is mostly just syntactic sugar; at the end of the day, the JavaScript runtime ends up doing what's shown in the first example, i.e. creating a constructor function and then adding the class's methods to the constructor function's prototype. Understanding protytypes is pretty useful. Understanding them means you understand how the entire JS class system works. And fortunately, protytypes aren't that big a cesspool if you've got a good teacher. Probably the best resource on the topic (even though it's quite old now) is JavaScript: The Good Parts. It's an easy read, and enjoyable because the author is a bit of a grump and isn't shy about noting the bad parts of JS along with the good ones. The book predates some of the newer syntax, like let, const, and even class. But if you keep in mind that the class syntax is really just using prototypes under the hood, then almost everything in the book will be very relevant to what you're doing now. One thing the book won't cover is Promises, along with how the new async/await that simplifies using Promises. Its very, very similar to how the async/await syntax in C# makes it easy to work with Tasks.

                                        T Offline
                                        T Offline
                                        thewazz
                                        wrote on last edited by
                                        #25

                                        awesome reply.

                                        1 Reply Last reply
                                        0
                                        • K Kirk 10389821

                                          my favorite feature is using || to override missing parameters!!! var timerSetting = paramTimer || userTimer || systemTimer || 500; the functions as parameters... That was a Throwback to CLIPPER days, where you had code snippets: {|| code} you could pass as parameters for event handlers, etc. Way cool... First language that I ever saw that in (probably because I took LISP later)... But you cdr guessed that. LOL I am HOPING that JavaScript replaces VBA as the internal scripting language of ALL programs! The more I use it, the more I like it. Kinda like JSON. The more you get used to it... the less you want to kill someone...

                                          K Offline
                                          K Offline
                                          kmoorevs
                                          wrote on last edited by
                                          #26

                                          Kirk 10389821 wrote:

                                          my favorite feature is using || to override missing parameters!!!

                                          Thanks, haven't tried that! :thumbsup: My favorite feature is writing a function that creates a new document on the fly, including functions/handlers of it's own, which in turn, creates functions/handlers for another new doc...:confused: but it works! :) (great way to control prints on tables)

                                          "Go forth into the source" - Neal Morse

                                          1 Reply Last reply
                                          0
                                          Reply
                                          • Reply as topic
                                          Log in to reply
                                          • Oldest to Newest
                                          • Newest to Oldest
                                          • Most Votes


                                          • Login

                                          • Don't have an account? Register

                                          • Login or register to search.
                                          • First post
                                            Last post
                                          0
                                          • Categories
                                          • Recent
                                          • Tags
                                          • Popular
                                          • World
                                          • Users
                                          • Groups