Peter Higgins is the Dojo Toolkit Project Lead. He gave a presentation on the history and use of the has() function in Dojo for feature detection. The has() function provides a way to write conditional code paths based on detected features. It has evolved from sniffing browsers to a more generic agnostic API. The Dojo builder uses the has() results to remove dead code paths and substitute variables.
5. /sigh
Sloppy code
Error prone
Difficult debugging / Build required
Single specific platform
Monday, September 19, 2011
6. embed.js / Uxebu
different direction, same idea: minimal bytes
per-function modules
minimal API surface (a la carte)
Dojo based, but not Dojo
Monday, September 19, 2011
7. Modernizr
new features, not old bugs.
up front testing, all tests always
dojo.uacss-style HTML classes
Monday, September 19, 2011
8. dojo-fd
dojo/trunk branch
Pure feature detection
first has() sighting
Monday, September 19, 2011
9. has.js
Feature detection API
Feature + Future tests available
Minimal bytes / No initial overhead
Simple API for configurable code paths
Generic / Agnostic
Monday, September 19, 2011
10. has() in Dojo: old “sniff”
require(["dojo/_base/sniff"], function(has){
has.add("some-magic", function(){
// randomly return true or false
return Math.random() > 0.5;
});
if(has("some-magic")){
// do it this way
}else{
// do it this way
}
});
Monday, September 19, 2011
11. has() in Dojo: plugin
define([
"dojo/has!native-array!mylib/Thinger!mylib/AltThinger"
], function(Thinger){
// Thinger is mylib/Thinger return if has("native-array")
// otherwise is mylib/AltThinger
// ideally they have the same API (a la embedjs)
});
Monday, September 19, 2011
12. Builder
hasMap in profile
variable substitution
dead path removal
Monday, September 19, 2011
14. Misc. Building
RequireJS
Dojo 1.7
ua-optimize https://github.com/kriszyp/ua-optimized
Monday, September 19, 2011
15. Detect or Assume
has() is agnostic
write own tests
document historic truth
limit impact of testing in production
10ms - 1800ms
Monday, September 19, 2011
16. WHERE
does this leave us?
Monday, September 19, 2011
17. AAAAND THANKS.
I promise I’m done talking.
Monday, September 19, 2011