Why is javascript in Windows 8 so anonymous and weird?

Why is javascript in Windows 8 so anonymous and weird?

  • Comments 4

I have been staring at javascript in Windows 8, and it just seems weird.  That anonymous thing with the empty set of parentheses at the end of the file.   Why is it anonymous, is it a criminal on the look out for the police? 

Here is what the code in one of the templates called “Blank App”, I don’t show the code above it. 

(function () {

//Code removed for brevity sake

};

    app.start();
})();
 

 

Why the empty parentheses?  This makes the function “anonymous”, why is the function “anonymous”?  Because it has no name!  It’s true.  This also means that we are able to do some cool things with the function.  For instance we are able to control controls.  Really, I didn’t just repeat the word control twice, one was the verb control and the other was the noun for objects that the user or system can interact with.  Sometimes we need to know the exact order of when controls are used.

This can be done using anonymous functions.  More in later blogs.

Leave a Comment
  • Please add 6 and 6 and type the answer here:
  • Post
  • You do this so that your code inside the outer function doesn't pollute the global namespace when you declare functions and variables. This is not to make it "anonymous".

  • Emmm.. your sample code contains unbalanced curly brackets.

    Btw, when you give the function a name and take it out, then replace the original part with the function name, it's really not that weird.

  • cheong00,

    Oops, unbalanced are my curly bracket and so is my brain.  Thank you for the feedback.  

    As to being weird, again, you are right.  But when I think about it, all of software is weird.  So JavaScript anonymous functions are part of the set of weird.  See set theory in use!

  • Jesse,

    Thank you for the comment, and you are right.  

Page 1 of 1 (4 items)
Generic Content

Legal Note:

  1. The author, Sam Stokes, is an employee of Microsoft
  2. There is no guarantee that anything I write is correct, I do try to make sure that what I write is correct.
  3. Use anything written in this blog at your own risk
  4. Test what I write about before using the information
  • Sometimes posts will disappear because I realized that they really don't fit with the total chaos of what I write about
  • Links are tested and available on date of publication, what others do with their links are out of my control

Restrictions:

  • Whatever I write on this blog is unedited by management or anyone, which should be obvious from the randomness of the blog.  I simply write about things I like.
  • Microsoft does not restrict me in anyway, so I generallyblather about whatever I want to.
  • For personal reasons I will not write about:
    • Company confidential stuff, mainly because Microsoft is more transparent than any company I have ever worked for.
    • Other people unless they give me permission to write about them