JavaScript: Constructor Auto-Execution with new Keyword
JavaScript is full of small, interesting facets that can trip you up, make you laugh, or make you cry. This post is about an interesting one. Those of you that have worked with JavaScript functions, and in a way JavaScript "classes" (as you used with MooTools), you're well acquainted with the new
keyword. With the new
keyword you get the ability to pass arguments with the function call, but did you know that if you have no arguments, you don't need the parens at all?
function MyClass() {
console.log('Initialized!');
//Set a property, as an example
this.dirty = true;
}
var instance = new MyClass;
// >> "Initialized!''
So why am I telling you this? I have no idea. It's just one of those fun tidbits that you can add to your brain. :)
![9 Mind-Blowing WebGL Demos]()
As much as developers now loathe Flash, we're still playing a bit of catch up to natively duplicate the animation capabilities that Adobe's old technology provided us. Of course we have canvas, an awesome technology, one which I highlighted 9 mind-blowing demos. Another technology available...
![From Webcam to Animated GIF: the Secret Behind chat.meatspac.es!]()
My team mate Edna Piranha is not only an awesome hacker; she's also a fantastic philosopher! Communication and online interactions is a subject that has kept her mind busy for a long time, and it has also resulted in a bunch of interesting experimental projects...
![Select Dropdowns, MooTools, and CSS Print]()
I know I've harped on this over and over again but it's important to enhance pages for print. You can do some things using simple CSS but today's post features MooTools and jQuery. We'll be taking the options of a SELECT element and generating...
![Build a Slick and Simple MooTools Accordion]()
Last week I covered a smooth, subtle MooTools effect called Kwicks. Another great MooTools creation is the Accordion, which acts like...wait for it...an accordion! Now I've never been a huge Weird Al fan so this is as close to playing an accordion as...
Amazing how the obvious is sometimes hidden in plain sight. I was going to save the extra () characters but it looks like there’s a micro performance hit in V8.
http://jsperf.com/new-with-and-without-parens
Really? That’s ironic, since Google Closure Compiler actually removes the parentheses when they can be omitted.
That was something I always was curious about but never bothered to ask/look up. I assume the same thing also occurs in php?
I’ll file this next to optional semi-colons and optional closing tags in HTML5: things that are interesting to know, but if I ever see while reviewing someone’s code I might get stabby.