473 captures
24 Mar 2010 - 11 Jan 2026
Sep OCT Nov
15
2019 2020 2021
success
fail

About this capture

COLLECTED BY

Collection: Corentin Barreau's Web Archives

Various web content archived by Corentin Barreau.
TIMESTAMPS

The Wayback Machine - http://web.archive.org/web/20201015162709/https://javascriptweblog.wordpress.com/
 
 

Behold, the new hotness! The shapely Arrow Function has driven away the irksome 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
 





 

If Hemingway Wrote JavaScript: Explained.

 

I wrote a book called If Hemingway Wrote JavaScript in which I imagine 25 famous novelists, poets and playwrights solving simple problems in JavaScript. Its part homage to my favorite writers and part love letter to JavaScript, the only language I know with enough freedom, creative potential and downright quirkiness to pique the interest of the literary greats.

Screen Shot 2015-01-04 at 4.33.55 PM
This post contains original material thats not in the book (think of it as one of those behind the scenes bonus features). Its the first in a series of deep technical dives into each authors solution. Some solutions require more explanation than others.

Enjoy!

 Continue reading If Hemingway Wrote JavaScript: Explained. 

 


Angus Croll

 

JavaScript Fat City

 

Its official! Were getting a new function syntax! The TC39 group (the panel charged with delivering ES 6) has reached consensus on an abbreviated syntax for JavaScript function expressions. Its popularly known as the fat arrow syntax, and is based on a similar construct found in CoffeeScript. 

Make no mistake, Im delighted that we will finally have an alternative to the unnecessary clunkiness and verbosity of the present grammar, but I cant shake a nagging feeling that this proposal (in its current form) is flawed to the extent that it might actually make new developers more confused than they already were. Ill run through the key features of this new construct, then explain my concerns and how they might be mitigated.

 Continue reading JavaScript Fat City 
 

Angus Croll

 
Standard 

Extending JavaScript Natives

 

Most built-in JavaScript types are constructors whose prototypes contain the methods and other properties that define their default behavior:
//(results will vary by browser)

Object.getOwnPropertyNames(Function.prototype)
//["bind", "arguments", "toString", "length", "call", "name", "apply", "caller", "constructor"]

You cant 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. Lets sift the danger from the dogma and try to reach an honest conclusion:

 Continue reading Extending JavaScript Natives 
 

Angus Croll
1
 
Standard 

Fixing the JavaScript typeof operator

 

Working with JavaScripts 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 Ill 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

 





 

Waldo: Search the JavaScript Object Model in under 1 KB

 

Heres a tiny util that you can save as a bookmarklet and use to crawl the JavaScript object model of any web site. Waldo (thanks to @shinypb for the name!) lets you find and inspect instances by name, type or value, and it can be easily customized to add additional tests. It runs in the console on Chrome, Firefox, Safari and IE>8. It's sourced on github. Feel free to fork it if you want to add more search methods or a spiffy UI.

(Update: Check out this alternate version by @jdalton) 


Continue reading Waldo: Search the JavaScript Object Model in under 1 KB 
 

Angus Croll

 


 

A fresh look at JavaScript Mixins

 

(Russian, Japanese)

In this article Ill explore JavaScript mixins in detail, and introduce a less conventional, but to my mind more natural mixin strategy that I hope youll find useful. Ill finish up with a profiler matrix summarizing the performance impact of each technique. [A big Thank You to the brilliant @kitcambridge for reviewing and improving the code on which this blog is based!]
 Continue reading A fresh look at JavaScript Mixins 
 

Angus Croll

 




 

JavaScript Strict Mode

 

The fifth edition of the ECMAScript specification introduced Strict Mode. Strict Mode imposes a layer of constraint on JavaScript  intended to protect you from the more perilous aspects of the language.

While researching this article I wrote 38 tests covering all the Strict Mode rules as defined in the ES5 specification. You can see how your favorite browser shapes up by clicking here.


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  lets dive in
 Continue reading JavaScript Strict Mode 
 

Angus Croll

 


 

The JavaScript Comma Operator

 

(на русском, )
 
Lets begin with a funny tweet:


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 youll ever need to know about JavaScripts bashful hero:
 Continue reading The JavaScript Comma Operator 
 

Angus Croll

 




 

Rethinking JavaScript Object Enumeration

 

In JavaScript, enumeration across regular (non-Array) Objects is often more painful than it should be. Arrays are merrily dispatched through 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 cant 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 dont. Until now, that is.
 Continue reading Rethinking JavaScript Object Enumeration 
 

Angus Croll
011
 


 

Posts navigation


Older posts
 


  Follow me on GitHubanguscroll.com
 




Create a free website or blog at WordPress.com.  





JavaScript, JavaScript 

Create a free website or blog at WordPress.com. 







Privacy & Cookies: This site uses cookies. By continuing to use this website, you agree to their use.
To find out more, including how to control cookies, see here: Cookie Policy