Friday, December 21st, 2007
Dean Edwards releases base2 and base2.DOM beta
<p>Dean Edwards has put base2 and base2.DOM out in beta:From now on base2 will be served from a permanent URL on googlecode. The URL will reflect the version number of the library. You can find the current (beta) libraries here.
base2.DOM has had a few months to mature now and there are no outstanding defects logged at googlecode. I’ll keep the code in beta for a month or two before issuing a final release. The API remains pretty much the same as when I first released base2.DOM. I have added some standards support to the style object but that’s about all.
I’m also releasing the core library, base2. I’ll blog more about this library sometime in the future. In the meantime you can browse the API and read the skeletal documentation
Dean wrote up an introduction to base2 where he covers the problems that he is trying to solve:
- Inconsistent enumeration across platforms
instanceofdoesn’t always worktypeofis inconsistent (RegExps identify as type “function†in Mozilla browsers)- Consistent object/platform detection
- Other various bugs
And the sugar:
- A mechanism for inheritance
- A decent hash object
- Array and String generics
- Array extras
- Support for ISO date parsing
Take a bit of time to look at the code as it is a great way to learn.
I like this little ditty:
-
-
detect: new function(_) {
-
// Two types of detection:
-
// 1. Object detection
-
// e.g. detect("(java)");
-
// e.g. detect("!(document.addEventListener)");
-
// 2. Platform detection (browser sniffing)
-
// e.g. detect("MSIE");
-
// e.g. detect("MSIE|opera");
-
-
var global = _;
-
var jscript = NaN/*@cc_on||@_jscript_version@*/; // http://dean.edwards.name/weblog/2007/03/sniff/#comment85164
-
var java = _.java ? true : false;
-
if (_.navigator) {
-
var element = document.createElement("span");
-
// Close up the space between name and version number.
-
// e.g. MSIE 6 -> MSIE6
-
var userAgent = navigator.platform + " " + navigator.userAgent.replace(/([a-z])[s/](d)/gi, "$1$2");
-
// Fix opera's (and others) user agent string.
-
if (!jscript) userAgent = userAgent.replace(/MSIE[d.]+/, "");
-
java &= navigator.javaEnabled();
-
}
-
-
return function(expression) {
-
var r = false;
-
var not = expression.charAt(0) == "!";
-
if (not) expression = expression.slice(1);
-
if (expression.charAt(0) == "(") {
-
// Object detection.
-
try {
-
eval("r=!!" + expression);
-
} catch (error) {
-
// the test failed
-
}
-
} else {
-
// Browser sniffing.
-
r = new RegExp("(" + expression + ")", "i").test(userAgent);
-
}
-
return !!(not ^ r);
-
};
-
}(this)
-
Related Content:











var element = document.createElement(“span”); ???
@Dion: Here’s the documentation for the detect() method that you like:
http://base2.googlecode.com/svn/doc/base2.html#/doc/!base2.detect