Bug Tracker

Ticket #6316: jQuery error - no arguments for methods.htm

File jQuery error - no arguments for methods.htm, 2.4 KB (added by Larry Battle, 12 years ago)

jQuery Error - no arguments with methods

Line 
1<!DOCTYPE html>
2<html>
3
4<!--
5
6  Created using http://jsbin.com
7  Source can be edited via http://jsbin.com/eriva/edit
8
9-->
10
11<head>
12<script class="jsbin" src="http://ajax.googleapis.com/ajax/libs/jquery/1/jquery.min.js"></script>
13<meta charset=utf-8 />
14<title>JS Bin</title>
15<!--[if IE]>
16  <script src="http://html5shiv.googlecode.com/svn/trunk/html5.js"></script>
17<![endif]-->
18<style>
19  article, aside, figure, footer, header, hgroup, 
20  menu, nav, section { display: block; }
21</style>
22</head>
23<body>
24  <p id="message"></p>
25  <p id="hello">Error with testing.</p>
26<script>/*
27Date: 03/18/2010
28Programmer: Larry Battle
29Library: jQuery 1.4.2
30Purpose: To show which method calls (with no arguments) from jQuery will produce an error.
31Example: If $( '#hello' ).css() is called, then the whole script will end with an error.
32Possible Fix: Check if needed variables exist before use.
33*/
34$(function(){
35
36  var mList = [], errorMethods = [], i = 0, method = '', message = '';
37  //Collect methods from jQuery namespace.
38  //All methods are given but different errors occur when $.prototype is used.
39  for( var methods in $ ){
40    if( $.prototype.hasOwnProperty( methods ) ){
41      mList.push( methods );
42    }
43  }
44 
45  mList = mList.sort();
46  //Test out method calls with no arguments.
47  i = mList.length;
48  while( i-- ){
49     method = mList[ i ];
50    try{
51        $.prototype[ method ]();
52    }
53    catch(err){
54      errorMethods.unshift( '<b>$.prototype.' + method + '()</b> FAILED. Error: ' + err);
55    }
56    if( method == 'error' ){ continue; } //An $(el).error() call will end the script.
57    try{
58        $('#hello')[ method ]();
59    }
60    catch(err2){
61      errorMethods.unshift( '<b>$( el ).' + method + '()</b> FAILED. Error: ' + err2 );
62    }
63  }
64  message = '<h1>-----Testing $.prototype.method() and $(el).method()------</h1>';
65  message += '<br/>Going through methods: ' + mList.sort().join(', ') + "<br/>----<br/>";
66  message += errorMethods.join( '<br/>' );
67 
68  $('#message').html( message );
69  $( '#hello' ).text( "Testing is Complete!" );
70});</script><script type="text/javascript">
71var gaJsHost = (("https:" == document.location.protocol) ? "https://ssl." : "http://www.");
72document.write(unescape("%3Cscript src='" + gaJsHost + "google-analytics.com/ga.js' type='text/javascript'%3E%3C/script%3E"));
73</script>
74<script type="text/javascript">
75var pageTracker = _gat._getTracker("UA-1656750-13");
76pageTracker._trackPageview();
77</script><script src="/js/render/edit.js"></script>
78</body>
79</html>