This Week in JavaScript - 18 November 2013

Your weekly update of interesting happenings in the world of JavaScript - feel free to discuss, and help to bring some new ideas to light.

Here’s what we’ve seen of interest this week.

For the designers

How to conveniently check for responsive breakpoints in JavaScript - When @media is not enough

Twitter Bootstrap 3 - The best Twitter Bootstrap JavaScript components and how to use them.

For the techies

RegExper - Craig Buckler tackles regular expressions

Understanding closures - A good, but “slightly misguided” explanation of closures (see myty’s comment below).

21 JavaScript Parts I Struggle To Remember - For the forgetful programmer

Libraries

Snap.svg - An open-source JavaScript library for browsers can give developers some of the features they miss as Flash fades from the Web.

Retire.js - Identify JavaScript libraries with known vulnerabilities in your application

Watching

Breaking Open: AngularJS (with Miško Hevery) - Simeon Franklin interviews AngularJS creator Miško Hevery

Resources

Free JS books - A list of web-based resources for your reading pleasure

Nothing to do with JS, but made me laugh

How can I pass the string “Null” through WSDL (SOAP) from ActionScript 3 - We have an employee whose last name is Null. He kills our employee lookup application when his last name is used as the search term …

[hr][/hr]
So, what you think about these recent happenings in JavaScript?
Do you hate closures, do you love regular expressions (weirdo!), or is Twitter Bootstrap the best thing since sliced bread?
Let us know and the debate can begin.

Also, feel free to PM Paul or [URL=“http://www.sitepoint.com/forums/private.php?do=newpm&u=184222”]PM Pullo if you have anything interesting for the next issue. Happy reading!

@Pullo;
Nice reading list!

And a bit misguided.

This works because in JavaScript parameters are passed by value, rather than by reference.

JavaScript is a pass by value language, and the i inside the function is a different chunk of memory than the i from the loop.

He’s wrong. Only primary types: string, number, boolean are passed by value. Complex types: array, function, object are passed by reference. He also should get the name shadowing concept first.


function changeNum(y) {
    y++;
    console.log(y); // y value is 2 after changeNum(x)
}

function changeObj(o) {
    o.one = "two";
}

var x = 1;
var obj = {one: "one"};

changeNum(x); // pass by value; it doesn't affect x
changeObj(obj); // pass by reference; it affects obj directly

console.log(x); // x value remains 1
console.log(obj); // obj's one property is changed to "two"

Hey @myty ;

Thanks for your comments and the code sample.
I’ve updated the links above to reflect this :slight_smile:

What do you mean by this?

He writes this:


for(var i=0;i<5;i++){
    (function(i){
        setTimeout(function(){
            alert(i)
        },i*100);
    })(i);
}

A re-write, for clearer understanding of scope and passed value:


for(var i=0;i<5;i++){
    (function(index){
        setTimeout(function(){
            alert(index)
        },i*100);
    })(i);
}

Notice how we can use i100 or index100 for setTimeout, with different outcomes. He is shadowing i, but he doesn’t understand it.

In other news ;), you seem to miss a big one, at least for some: Dart has reached 1.0.

Ah ok, got ya. Thanks.
I found it on Wikipedia, too: http://en.wikipedia.org/wiki/Variable_shadowing

I did read about this, but wasn’t sure how “newsworthy” it was.
Do you have any experience using Dart?

No. This note is what is turning me off:

Note: You can write Dart apps using any recent version of Windows (Vista, 7, or 8), Linux, or Mac. The Dart development tools do not support Windows XP. Dart Editor requires Java version 6 or higher.

I can understand Windows XP not being supported. But Java requirements are just too much for me. Never really got Java on my good side.

I believe this link has more JavaScript specific info about scope and shadowing: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Scope_Cheatsheet