DailyJS

DailyJS

The JavaScript blog.


Tagresources
Featured

resources hardware libraries node browser

Myo.js, JavaScript.com

Posted on .

Myo.js

Myo

Myo from Thalmic Labs is a gesture control armband that's described as a "wearable presentation remote". Paul Bernhardt from Thalmic Labs sent me myo.js (GitHub: thalmiclabs/myo.js, License: BSD 3-Clause, npm: myo), a JavaScript library for interacting with the device. It uses WebSockets to talk to Myo Connect, which runs on your desktop.

The API is based around events. Here's a quick example:

myMyo.on('gyroscope', function(data) {  
  if (data.x > 100){
    alert('Woah now!')
  }
});

It also supports "poses", for example: myMyo.on('thumb_to_pinky', cb).

The API is pretty well documented, with method documentation and examples in the readme. There's also a blog post that introduces Myo.js.

JavaScript.com

JavaScript.com

Code School, the web-based subscription tutorial site, has recently launched javascript.com. It has an interactive tutorial, a blog, and resources to help beginners.

Naturally it promotes Code School (owned by Pluralsight), but it's nice to see something useful and well designed there. It used to have a very dated internet.com page, so Code School's page is a step up.

Featured

tutorials resources books

Learning Advanced JavaScript

Posted on .

Many readers have been asking me how to learn JavaScript beyond simple
web interface hacking. People are transitioning from those who consume
JavaScript resources as a way to implement web design to full-blown
JavaScript developers -- reaching out beyond jQuery and similar
frameworks to discover graphical libraries and unit testing systems.

Here are a few ideas and tips to learn advanced JavaScript.

Prototype

Unlock the power of prototypal inheritance early on. If you're using a
library to write object-oriented JavaScript, try writing a project using
only JavaScript's built-in prototypal inheritance.

You'll learn a lot about JavaScript very quickly, and learn to use
anonymous functions to elegantly plug the gaps in the language -- using
functions as namespaces and other interesting tricks.

You don't actually need OO libraries in JavaScript once you master
these techniques.

Mistaken Assumptions

If you're already familiar with C, Java, Ruby, Python and so on you
might have incorrect preconceptions about how JavaScript works.

One fun little surprise is block scopes -- or the lack of them. Blocks
don't introduce scope, there's only function-level scope. If you start a
block with for or if and there are
var delcarations inside it, those variables will be visible
to the entire function.

Another little surprise is the behaviour of the equality operator:
== doesn't always behave as you'd expect:

js> '' == '0'
false
js> 0 == ''
true

If this has got you worried, I recommend:

Reading Code

Another way to pick up more advanced JavaScript is to read what other
people have written. There are loads of great JavaScript authors writing
open source code:

  • John Resig has a great blog and exciting projects like jQuery, Processing.js and Sizzle.js
  • Sam Stephenson wrote Prototype and a bunch of other cool stuff like Sprockets
  • Thomas Fuchs is the author of scriptaculous -- his code is a good source to learn how animation in JavaScript/HTML works (try reading emile.js)
  • Ryan Dahl who wrote node.js has some interesting projects
  • TJ Holowaychuk has written a tonne of interesting projects, like ext.js, express and jspec

A good way to learn techniques this way is to look out for common
patterns, then figure out how they work when you need them. For example,
if you like the way JSpec's API has its own DSL and you'd like to write
a JavaScript DSL for a project, pick apart JSpec and see how it works.

Authors

Through my own years of JavaScript hacking, I've always gone back to
Douglas Crockford's work.

David Flanagan, the author of JavaScript: The Definitive Guide is another authority on
the topic. He blogs about JavaScript and has recently written about
CommonJS.