Tham khảo tài liệu 'phát triển javascript - part 24', công nghệ thông tin, kỹ thuật lập trình phục vụ nhu cầu học tập, nghiên cứu và làm việc hiệu quả | Using Object Detection for Good 203 Listing Unfriendly Host object behavior TestCase HostObjectTest test IE host object behavior function var xhr new ActiveXObject assertException function if Expectation property exists Reality exception is thrown assertEquals unknown typeof var element div assertEquals unknown typeof assertException function In his article Feature Detection State of the Art Browser Scripting 1 Peter Michaux provides the isHostMethod method shown in Listing to help with feature detection and host methods. Listing Checking if a host object is callable function function isHostMethod object property var type typeof object property return type function type object object property type unknown return isHostMethod 1. http articles feature-detection-state-of-the-art-browser-scripting Download from 204 Feature Detection This method is able to recognize callable host objects based on the following observations ActiveX properties always have a typeof result of unknown. Non-ActiveX callable host objects in Internet Explorer usually have a typeof result of object. The boolean coercion is required to avoid null which also has a typeof result of object. In other browsers callable objects tend to have a typeof result of function even host methods Using this helper we can improve our cross-browser event handler as seen in Listing . Listing Improved feature detection for addEventHandler function addEventHandler element type listener if element addEventListener type listener false else if element attachEvent on type function return element else Possibly fall back to DOM0 event properties or abort Sample Use Testing Testing for the existence and type of an .