Comments on: Global Domination, Part Two http://yuiblog.com/blog/2008/04/16/global-domination-part-two/ News and Artilces about Designing and Developing with Yahoo! Libraries. Thu, 07 Aug 2008 11:24:54 +0000 http://wordpress.org/?v=2.3.3 By: scriptNode / My New Coding Habits http://yuiblog.com/blog/2008/04/16/global-domination-part-two/#comment-436044 scriptNode / My New Coding Habits Sun, 03 Aug 2008 05:24:34 +0000 http://yuiblog.com/blog/2008/04/16/global-domination-part-two/#comment-436044 [...] be lying if I said I wasn't externally influenced on this one. Douglas Crockford has a lot of great recommendations, and this is one I tend to agree [...] […] be lying if I said I wasn’t externally influenced on this one. Douglas Crockford has a lot of great recommendations, and this is one I tend to agree […]

]]>
By: Frode Danielsen http://yuiblog.com/blog/2008/04/16/global-domination-part-two/#comment-365059 Frode Danielsen Fri, 02 May 2008 02:30:08 +0000 http://yuiblog.com/blog/2008/04/16/global-domination-part-two/#comment-365059 The "var pity = this.pity || {}" and it's variants has become quite popular in recent Javascript libraries, and I like it myself. You'll have to give in to the assumption that you use it in places where booleans are not values you expect. One of the most useful cases for me would be as a default value for function parameters. Consider: function doSomething (a) { a = a || 'defaultValue'; } If the variable 'a' is undefined here, it will get a default value instead, making the variable 'a' useful to the rest of the function. Though if you prefer, I guess it could be written as: function doSomething (a) { a = (a !== undefined ? a : 'defaultValue'); } The “var pity = this.pity || {}” and it’s variants has become quite popular in recent Javascript libraries, and I like it myself. You’ll have to give in to the assumption that you use it in places where booleans are not values you expect.

One of the most useful cases for me would be as a default value for function parameters. Consider:

function doSomething (a) {
a = a || ‘defaultValue’;
}

If the variable ‘a’ is undefined here, it will get a default value instead, making the variable ‘a’ useful to the rest of the function.

Though if you prefer, I guess it could be written as:

function doSomething (a) {
a = (a !== undefined ? a : ‘defaultValue’);
}

]]>
By: Zach Leatherman http://yuiblog.com/blog/2008/04/16/global-domination-part-two/#comment-355852 Zach Leatherman Tue, 22 Apr 2008 03:07:49 +0000 http://yuiblog.com/blog/2008/04/16/global-domination-part-two/#comment-355852 I would think that it is common knowledge to check <code>typeof pity === 'undefined'</code>, instead of using a construct like <code>var pity = this.pity || {};</code>, especially assuming that the code in question is the byproduct of a reasonably adaptive program. If you assume that the web developer audiences that program in ignorance of the language and the readership of this blog (or the readership of any JavaScript blog author who adopts this method) are mutually exclusive, then one might trend towards agreeing your third form is appropriate. But, seeing that most developers "learn" from copy and paste, it would seem that the second form would be safer, if for no other reason than to prevent those abominable globals we all abhor. I would think that it is common knowledge to check typeof pity === 'undefined', instead of using a construct like var pity = this.pity || {};, especially assuming that the code in question is the byproduct of a reasonably adaptive program.

If you assume that the web developer audiences that program in ignorance of the language and the readership of this blog (or the readership of any JavaScript blog author who adopts this method) are mutually exclusive, then one might trend towards agreeing your third form is appropriate.

But, seeing that most developers “learn” from copy and paste, it would seem that the second form would be safer, if for no other reason than to prevent those abominable globals we all abhor.

]]>
By: Administrator http://yuiblog.com/blog/2008/04/16/global-domination-part-two/#comment-355045 Administrator Mon, 21 Apr 2008 11:22:12 +0000 http://yuiblog.com/blog/2008/04/16/global-domination-part-two/#comment-355045 Testing the comment system, which was down for a while there. Everything seems back to normal, though, so give it a go! Testing the comment system, which was down for a while there. Everything seems back to normal, though, so give it a go!

]]>