Judging method
The code is as follows |
Copy Code |
typeof (Test) = = "function" Boolean (Window.loginok instanceof Function) Boolean (window.parent.loginOk instanceof function)//judging functions in the parent page |
And then I sorted out a
The code is as follows |
Copy Code |
Window.onload=function () { try{
if (test&&typeof (TEST) = = "function") { Test (); }else{ Alert ("nonexistent function"); } }catch (e) { } } function Test () { Alert ("Function execution ..."); }
|
If it does not exist, an exception is thrown, so add try......catch.
Example
It's okay to use typeof even if it doesn't exist, which is the test code:
The code is as follows |
Copy Code |
<script type= "Text/javascript" //Window scope alert (typeof (AAAAA)); //Custom scope var Type = function () {} type.prototype.test = function () {alert (typeof bb BB)); }; var obj = new type (); obj.test (); </script> <body> </body> |