| Sep | OCT | Nov |
| 15 | ||
| 2019 | 2020 | 2021 |
COLLECTED BY
Collection: Corentin Barreau's Web Archives
function keyword and (by virtue of lexical this scoping) bought joy to many a JavaScript programmer. Yet, as the following account relates, even the best tools should be used with discretion. Continue reading “Of Classes and Arrow Functions (a cautionary tale)”
●Angus Croll
●5
●arrow functions
●bind
●class
●Javascript
This post contains original material that’s not in the book (think of it as one of those “behind the scenes” bonus features). It’s the first in a series of deep technical dives into each author’s solution. Some solutions require more explanation than others.
Enjoy!
Continue reading “If Hemingway Wrote JavaScript: Explained.”
●Angus Croll
●
//(results will vary by browser) Object.getOwnPropertyNames(Function.prototype) //["bind", "arguments", "toString", "length", "call", "name", "apply", "caller", "constructor"]You can’t delete or replace a native prototype, but you can edit the values of its properties, or create new ones:
//create a new array method that removes a member
Array.prototype.remove = function(member) {
var index = this.indexOf(member);
if (index > -1) {
this.splice(index, 1);
}
return this;
}
['poppy', 'sesame', 'plain'].remove('poppy'); //["sesame", "plain"]
['ant', 'bee', 'fly'].remove('spider'); //["ant", "bee", "fly"]
Et voila! Our code gets a useful array extension for free. However if you brag about doing this in production code, expect to get pummeled by a wave of fierce disapproval. Some of it carries weight. Let’s sift the danger from the dogma and try to reach an honest conclusion:
Continue reading “Extending JavaScript Natives”
●Angus Croll
●1
Standard
typeof operator is a bit like operating a clapped-out old car (or an early model Dell Inspiron). It gets the job done (mostly) and you learn to work around the quirks – but you probably aspire to something better.
In this article I’ll give a brief overview of typeof before introducing a tiny new function which is a fully-loaded, more reliable alternative that works directly with the language internals.
Continue reading “Fixing the JavaScript typeof operator”
●Angus Croll
●
●class
●duck-typing
●instanceof
●typeof

The code for each test is reproduced at the end of the article as an aid to understanding the specification. You can also run the tests manually by copying and pasting the source into the console. The full source code is on my github repo.
Firefox 4 and IE10 (preview 1) already fully support Strict Mode, and Chrome 12 is nearly there. Strict Mode is here to stay – let’s dive in…
Continue reading “JavaScript Strict Mode”
●Angus Croll
●
●strict mode
The ‘c’ at the end is for the lowly comma operator. Last in the line of operator precedence and rarely documented, the comma operator hides its light under a bushel. It may not be a JavaScript heavy-hitter but I like it anyway. Its simple, elegant and you should make it your friend. So, here we go – more than you’ll ever need to know about JavaScript’s bashful hero:
Continue reading “The JavaScript Comma Operator”
●Angus Croll
●
●comma
●eval
●operator precedence
for and while loops using all manner of crazy, fun techniques; Objects are forever at the mercy of the pedestrian, one directional for-in loop, without which we can’t even learn the names and length of its own property set. Arrays have access to a plethora of elegant higher order functions (forEach, map, filter etc.); Objects don’t. Until now, that is.
Continue reading “Rethinking JavaScript Object Enumeration”
●Angus Croll
●011
●object keys arrays
Create a free website or blog at WordPress.com.
JavaScript, JavaScript…
Create a free website or blog at WordPress.com.