On Thu, Oct 6, 2011 at 2:17 PM, Fyodorov "bga" Alexander <
[email protected]> wrote:
>
> 1) convert your code to
> {
> const singletonObject = (function(){
> // helper fns
>
> return {
> // privare members
> newsItems_: [],
>
> _init: function(){
> // your object init here
> delete this._init // prevent double init
>
I recommend against using delete in objects that are not used as
dictionaries. In modern Javascript engines, this might throw off the "hidden
class" optimizations for the object and make it it slower
Just have the init function next to the object and call it as:
return init.call({...my object literal...});
for the same effect - or just inline the code in the anonymous function
instead of introducing an extra initialization function. After all, the
anonymous function's job is to create that object.
return this
> },
>
> // methods
> getFilters: function(){
>
> }
> }._init()
> })()
> }
>
...
> 5) you can forget about semicolon
>
No, please don't. It doesn't make code more readable, and it can make
introduce subtle bugs if you don't know when semicolon is needed.
/L
--
To view archived discussions from the original JSMentors Mailman list:
http://www.mail-archive.com/[email protected]/
To search via a non-Google archive, visit here:
http://www.mail-archive.com/[email protected]/
To unsubscribe from this group, send email to
[email protected]