Javascript and new way of thinking!

It’s been quite some time since I did any Javascript programming, and it’s hard to start thinking in an unstructured way again.  One of JS’s peculiar nuances is the ability to declare a property on an object by just assigning it! After working with C++/Obj C/C# and having to declare everything up front this takes a new way of thinking.

For instance, with the Cocos2D-X-JS the pattern of their script declaration didn’t make it obvious on where or how to declare variables that will persist between function calls.  Being used to pre-declaring everything, I stuck a few ‘var’ statements at the top of the file, before the ‘extends’ stuff starts.  This works, but looks a bit messy.

var self,canvas;

extends: cc.Component,

Of course, with JS, there’s no need to declare variables, just assign them as a property and they’re created for you!  Of course, you’ll not get the benefit of type checking and even checking if the var you’re using is spelt the same as the one you declared, but you can’t have everything!

One thought on “Javascript and new way of thinking!

Leave a Reply