[dojo-contributors] Prototype-al simplicity

Bill Keese bill at dojotoolkit.org
Fri Apr 7 13:31:16 EDT 2006


Tom Trenka wrote:
> For instance, instead of:
> 
>     getViewportWidth 
>     getViewportHeight 
> 
> ...we'd have this:
> 
> object getViewportSize
> 
> ...where the return object would look like:
> { width:..., height:... }

That probably makes sense.  And in some cases (when the calling code 
needs both width and height), performance will probably improve.

A few other things:
  - lots of deprecated functions that can be removed

  - coordinates are handled both as an array [5,7] and an object {w: 5, 
h: 7}.  Just an object should be sufficient.


Just in general I would take error checking and weird case handling out 
of functions.  For example, here is a current setClass() function:

dojo.html.setClass = function(node, classStr){
	node = dojo.byId(node);
	if(!node){ return false; }
	var cs = new String(classStr);
	try{
		if(typeof node.className == "string"){
			node.className = cs;
		}else if(node.setAttribute){
			node.setAttribute("class", classStr);
			node.className = cs;
		}else{
			return false;
		}
	}catch(e){
		dojo.debug("dojo.html.setClass() failed", e);
	}
	return true;
}

I'm tempted to rewrite it as below:

dojo.html.setClass = function(node, classStr){
	node = dojo.byId(node);
	if(typeof node.className == "string"){
		node.className = cs;
	}else{
		node.setAttribute("class", classStr);
	}
}




More information about the dojo-contributors mailing list