Javascript
-
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
andbind
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 ofprototype
. 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
Question #1: Who are you, and what have you done with our Marc Clifton? Question #2: Why didn't you bring enough to share, dude?
Software Zen:
delete this;
-
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
andbind
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 ofprototype
. 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
-
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
andbind
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 ofprototype
. 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
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.
-
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
andbind
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 ofprototype
. 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
-
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
andbind
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 ofprototype
. 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
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 -
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
andbind
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 ofprototype
. 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
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
-
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
andbind
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 ofprototype
. 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
Marc Clifton wrote:
this
andbind
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:
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.
-
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
andbind
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 ofprototype
. 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
-
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
andbind
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 ofprototype
. 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
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
-
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.
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
-
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
andbind
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 ofprototype
. 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
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...? :DBest, Sander Continuous Integration, Delivery, and Deployment arrgh.js - Bringing LINQ to JavaScript Object-Oriented Programming in C# Succinctly
-
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.
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.
-
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
andbind
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 ofprototype
. 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
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?"
-
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
andbind
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 ofprototype
. 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
-
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...? :DBest, Sander Continuous Integration, Delivery, and Deployment arrgh.js - Bringing LINQ to JavaScript Object-Oriented Programming in C# Succinctly
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. -
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.
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.
-
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
Koolaid?
Wrong is evil and must be defeated. - Jeff Ello
-
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...? :DBest, Sander Continuous Integration, Delivery, and Deployment arrgh.js - Bringing LINQ to JavaScript Object-Oriented Programming in C# Succinctly
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 overkillAt 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
-
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, 2013John 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
-
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
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