Comments on: Global Domination http://yuiblog.com/blog/2006/06/01/global-domination/ News and Artilces about Designing and Developing with Yahoo! Libraries. Sun, 11 May 2008 13:33:52 +0000 http://wordpress.org/?v=2.3.3 By: Dr. Prolix » Blog Archive » Enliven your namespaces http://yuiblog.com/blog/2006/06/01/global-domination/#comment-364802 Dr. Prolix » Blog Archive » Enliven your namespaces Thu, 01 May 2008 17:10:19 +0000 http://yuiblog.com/blog/2006/06/01/global-domination/#comment-364802 [...] to use namespaces when writing your JavaScript. The reasons why have been stated time and again by much smarter and more eloquent people than myself, so suffice it to say, you should do [...] […] to use namespaces when writing your JavaScript. The reasons why have been stated time and again by much smarter and more eloquent people than myself, so suffice it to say, you should do […]

]]>
By: Vayn技术网摘 » 窥探jQuery http://yuiblog.com/blog/2006/06/01/global-domination/#comment-302154 Vayn技术网摘 » 窥探jQuery Mon, 11 Feb 2008 00:45:38 +0000 http://yuiblog.com/blog/2006/06/01/global-domination/#comment-302154 [...] 编写可重用的、优秀的JavaScript代码,其关键在于对名称空间的积极把控。JavaScript只拥有单一的、全局的名称空间(即window对象),而很多程序员(以及一些库)恣意地为之添加各种东西。要知道全局变量是魔鬼!聪明的开发人员,会使用类似组件模式的技术,来尽力减少全局对象的数量。 [...] […] 编写可重用的、优秀的JavaScript代码,其关键在于对名称空间的积极把控。JavaScript只拥有单一的、全局的名称空间(即window对象),而很多程序员(以及一些库)恣意地为之添加各种东西。要知道全局变量是魔鬼!聪明的开发人员,会使用类似组件模式的技术,来尽力减少全局对象的数量。 […]

]]>
By: timothy http://yuiblog.com/blog/2006/06/01/global-domination/#comment-294549 timothy Thu, 31 Jan 2008 23:43:37 +0000 http://yuiblog.com/blog/2006/06/01/global-domination/#comment-294549 >>OK, but if I document it, then anyone can see it’s intentional: Comments are not durable. I've known programmers who strip all comments upon opening a source file. The justification they give? "Comments are always wrong." My translation of that is that code can be changed without changing the comments, so the comments don't necessarily apply to the code that you see. Making the code clear enough that it doesn't need comments is the best way to go. >>OK, but if I document it, then anyone can see it’s intentional:

Comments are not durable. I’ve known programmers who strip all comments upon opening a source file. The justification they give? “Comments are always wrong.” My translation of that is that code can be changed without changing the comments, so the comments don’t necessarily apply to the code that you see.

Making the code clear enough that it doesn’t need comments is the best way to go.

]]>
By: zachleat.com {web} » Namespacing outside of the YAHOO Namespace http://yuiblog.com/blog/2006/06/01/global-domination/#comment-180825 zachleat.com {web} » Namespacing outside of the YAHOO Namespace Wed, 29 Aug 2007 01:34:32 +0000 http://yuiblog.com/blog/2006/06/01/global-domination/#comment-180825 [...] Global Domination, an article written by Douglas Crockford [...] […] Global Domination, an article written by Douglas Crockford […]

]]>
By: Julien Lecomte’s Blog » Introducing the YUI Compressor http://yuiblog.com/blog/2006/06/01/global-domination/#comment-172114 Julien Lecomte’s Blog » Introducing the YUI Compressor Tue, 14 Aug 2007 23:39:58 +0000 http://yuiblog.com/blog/2006/06/01/global-domination/#comment-172114 [...] doesn’t obfuscate global symbols, and 2) you won’t pollute the global object (see this great article by Douglas [...] […] doesn’t obfuscate global symbols, and 2) you won’t pollute the global object (see this great article by Douglas […]

]]>
By: Foo Hack » YUI’s “Module Pattern” vs. Prototype’s Class Function http://yuiblog.com/blog/2006/06/01/global-domination/#comment-171542 Foo Hack » YUI’s “Module Pattern” vs. Prototype’s Class Function Mon, 13 Aug 2007 17:54:08 +0000 http://yuiblog.com/blog/2006/06/01/global-domination/#comment-171542 [...] (When in doubt, wrap it in a closure. Global variables are evil.) [...] […] (When in doubt, wrap it in a closure. Global variables are evil.) […]

]]>
By: A JavaScript Module Pattern » Yahoo! User Interface Blog http://yuiblog.com/blog/2006/06/01/global-domination/#comment-139717 A JavaScript Module Pattern » Yahoo! User Interface Blog Tue, 12 Jun 2007 20:28:51 +0000 http://yuiblog.com/blog/2006/06/01/global-domination/#comment-139717 [...] Global variables are evil. Within YUI, we use only two globals: YAHOO and YAHOO_config. Everthing in YUI makes use of members within the YAHOO object hierarchy or variables that are scoped to such a member. We advise that you exercise similar discipline in your own applications, too. [...] […] Global variables are evil. Within YUI, we use only two globals: YAHOO and YAHOO_config. Everthing in YUI makes use of members within the YAHOO object hierarchy or variables that are scoped to such a member. We advise that you exercise similar discipline in your own applications, too. […]

]]>
By: Andrea Ercolino http://yuiblog.com/blog/2006/06/01/global-domination/#comment-45938 Andrea Ercolino Sat, 10 Feb 2007 01:41:44 +0000 http://yuiblog.com/blog/2006/06/01/global-domination/#comment-45938 OK, but if I document it, then anyone can see it's intentional: <code> YAHOO = {}; //implied global </code> --- I think the YAHOO's declaration can be improved: <code> switch( typeof YAHOO ) { case "undefined": var YAHOO = {}; break; default: YAHOO = {}; //a proper re-definition } </code> OK, but if I document it, then anyone can see it’s intentional:

YAHOO = {}; //implied global

I think the YAHOO’s declaration can be improved:

switch( typeof YAHOO ) {
case "undefined":
var YAHOO = {};
break;
default:
YAHOO = {}; //a proper re-definition
}

]]>
By: Douglas Crockford http://yuiblog.com/blog/2006/06/01/global-domination/#comment-45762 Douglas Crockford Fri, 09 Feb 2007 17:38:43 +0000 http://yuiblog.com/blog/2006/06/01/global-domination/#comment-45762 I like #1 because it doesn't look like an accident. I don't like JavaScript's implied global policy; I think it was a mistake. So I like all declarations, including global declarations, to be explicit. I like #1 because it doesn’t look like an accident. I don’t like JavaScript’s implied global policy; I think it was a mistake. So I like all declarations, including global declarations, to be explicit.

]]>
By: Andrea Ercolino http://yuiblog.com/blog/2006/06/01/global-domination/#comment-44954 Andrea Ercolino Thu, 08 Feb 2007 02:15:06 +0000 http://yuiblog.com/blog/2006/06/01/global-domination/#comment-44954 > Ideally, an application, library, component, or widget defines only a single global variable. Agreed, but how does it define the global variable? 1: var YAHOO = {}; 2: YAHOO = {}; 3: window.YAHOO = {}; 4: self.YAHOO = {}; I think #2 is the best way, but what is the reason for using #1 in YUI? > Ideally, an application, library, component, or widget defines only a single global variable.

Agreed, but how does it define the global variable?

1: var YAHOO = {};
2: YAHOO = {};
3: window.YAHOO = {};
4: self.YAHOO = {};

I think #2 is the best way, but what is the reason for using #1 in YUI?

]]>