SitePoint Sponsor

User Tag List

Results 1 to 6 of 6
  1. #1
    Gre aus'm Pott gold trophysilver trophybronze trophy
    Pullo's Avatar
    Join Date
    Jun 2007
    Location
    Germany
    Posts
    5,895
    Mentioned
    212 Post(s)
    Tagged
    12 Thread(s)

    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 ...



    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 PM Pullo if you have anything interesting for the next issue. Happy reading!
    Last edited by Pullo; Nov 18, 2013 at 05:03.

  2. #2
    Non-Member
    Join Date
    Feb 2012
    Posts
    892
    Mentioned
    10 Post(s)
    Tagged
    0 Thread(s)
    @Pullo ;
    Nice reading list!

    Quote Originally Posted by Pullo View Post
    Understanding closures - Bills itself as a "very practical explanation of closures"
    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.

    Code:
    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"

  3. #3
    Gre aus'm Pott gold trophysilver trophybronze trophy
    Pullo's Avatar
    Join Date
    Jun 2007
    Location
    Germany
    Posts
    5,895
    Mentioned
    212 Post(s)
    Tagged
    12 Thread(s)
    Hey @myty ;

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

    Quote Originally Posted by myty View Post
    He also should get the name shadowing concept first.
    What do you mean by this?

  4. #4
    Non-Member
    Join Date
    Feb 2012
    Posts
    892
    Mentioned
    10 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by Pullo View Post
    What do you mean by this?
    He writes this:
    Code:
    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:

    Code:
    for(var i=0;i<5;i++){
        (function(index){
            setTimeout(function(){
                alert(index)
            },i*100);
        })(i);
    }
    Notice how we can use i*100 or index*100 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.

  5. #5
    Gre aus'm Pott gold trophysilver trophybronze trophy
    Pullo's Avatar
    Join Date
    Jun 2007
    Location
    Germany
    Posts
    5,895
    Mentioned
    212 Post(s)
    Tagged
    12 Thread(s)
    Quote Originally Posted by myty View Post
    Notice how we can use i*100 or index*100 for setTimeout, with different outcomes. He is shadowing i, but he doesn't understand it.
    Ah ok, got ya. Thanks.
    I found it on Wikipedia, too: http://en.wikipedia.org/wiki/Variable_shadowing

    Quote Originally Posted by myty View Post
    In other news , you seem to miss a big one, at least for some: Dart has reached 1.0.
    I did read about this, but wasn't sure how "newsworthy" it was.
    Do you have any experience using Dart?

  6. #6
    Non-Member
    Join Date
    Feb 2012
    Posts
    892
    Mentioned
    10 Post(s)
    Tagged
    0 Thread(s)
    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/...ope_Cheatsheet


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •