HTML and CSS Reference
In-Depth Information
Listing 10.6 Unfriendly Host object behavior
TestCase("HostObjectTest", {
"test IE host object behavior": function () {
var xhr = new ActiveXObject("Microsoft.XMLHTTP");
assertException(function () {
if (xhr.open) {
// Expectation: property exists
// Reality: exception is thrown
}
});
assertEquals("unknown", typeof xhr.open);
var element = document.createElement("div");
assertEquals("unknown", typeof element.offsetParent);
assertException(function () {
element.offsetParent;
});
}
});
In his article, “Feature Detection: State of the Art Browser Scripting” 1 , Peter
Michaux provides the isHostMethod method shown in Listing 10.7 to help with
feature detection and host methods.
Listing 10.7 Checking if a host object is callable
tddjs.isHostMethod = (function () {
function isHostMethod(object, property) {
var type = typeof object[property];
return type == "function" ||
(type == "object" && !!object[property])
||
type == "unknown";
}
return isHostMethod;
}());
1. http://peter.michaux.ca/articles/feature-detection-state-of-the-art-browser-scripting
 
Search WWH ::




Custom Search