Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
J
jquery
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
夏彬
jquery
Commits
7d0a8419
Commit
7d0a8419
authored
Mar 16, 2007
by
John Resig
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Added all the tests for isFunction, fixed bug #1026.
parent
297a450e
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
77 additions
and
1 deletion
+77
-1
coreTest.js
src/jquery/coreTest.js
+76
-0
jquery.js
src/jquery/jquery.js
+1
-1
No files found.
src/jquery/coreTest.js
View file @
7d0a8419
...
@@ -19,6 +19,82 @@ test("$()", function() {
...
@@ -19,6 +19,82 @@ test("$()", function() {
$
(
'<p>
\
r
\
n</p>'
);
$
(
'<p>
\
r
\
n</p>'
);
});
});
test
(
"isFunction"
,
function
()
{
expect
(
20
);
// Make sure that false values return false
ok
(
!
jQuery
.
isFunction
(),
"No Value"
);
ok
(
!
jQuery
.
isFunction
(
null
),
"null Value"
);
ok
(
!
jQuery
.
isFunction
(
undefined
),
"undefined Value"
);
ok
(
!
jQuery
.
isFunction
(
""
),
"Empty String Value"
);
ok
(
!
jQuery
.
isFunction
(
0
),
"0 Value"
);
// Check built-ins
// Safari uses "(Internal Function)"
ok
(
jQuery
.
isFunction
(
String
),
"String Function"
);
ok
(
jQuery
.
isFunction
(
Array
),
"Array Function"
);
ok
(
jQuery
.
isFunction
(
Object
),
"Object Function"
);
ok
(
jQuery
.
isFunction
(
Function
),
"Function Function"
);
// When stringified, this could be misinterpreted
var
mystr
=
"function"
;
ok
(
!
jQuery
.
isFunction
(
mystr
),
"Function String"
);
// When stringified, this could be misinterpreted
var
myarr
=
[
"function"
];
ok
(
!
jQuery
.
isFunction
(
myarr
),
"Function Array"
);
// When stringified, this could be misinterpreted
var
myfunction
=
{
"function"
:
"test"
};
ok
(
!
jQuery
.
isFunction
(
myfunction
),
"Function Object"
);
// Make sure normal functions still work
var
fn
=
function
(){};
ok
(
jQuery
.
isFunction
(
fn
),
"Normal Function"
);
var
obj
=
document
.
createElement
(
"object"
);
// Firefox says this is a function
ok
(
!
jQuery
.
isFunction
(
obj
),
"Object Element"
);
// IE says this is an object
ok
(
jQuery
.
isFunction
(
obj
.
getAttribute
),
"getAttribute Function"
);
var
nodes
=
document
.
body
.
childNodes
;
// Safari says this is a function
ok
(
!
jQuery
.
isFunction
(
nodes
),
"childNodes Property"
);
var
first
=
document
.
body
.
firstChild
;
// Normal elements are reported ok everywhere
ok
(
!
jQuery
.
isFunction
(
first
),
"A normal DOM Element"
);
var
input
=
document
.
createElement
(
"input"
);
input
.
type
=
"text"
;
document
.
body
.
appendChild
(
input
);
// IE says this is an object
ok
(
jQuery
.
isFunction
(
input
.
focus
),
"A default function property"
);
document
.
body
.
removeChild
(
input
);
// Recursive function calls have lengths and array-like properties
function
callme
(
callback
){
function
fn
(
response
){
callback
(
response
);
}
ok
(
jQuery
.
isFunction
(
fn
),
"Recursive Function Call"
);
fn
({
some
:
"data"
});
};
callme
(
function
(){
callme
(
function
(){});
});
});
test
(
"length"
,
function
()
{
test
(
"length"
,
function
()
{
ok
(
$
(
"div"
).
length
==
2
,
"Get Number of Elements Found"
);
ok
(
$
(
"div"
).
length
==
2
,
"Get Number of Elements Found"
);
});
});
...
...
src/jquery/jquery.js
View file @
7d0a8419
...
@@ -1255,7 +1255,7 @@ jQuery.extend({
...
@@ -1255,7 +1255,7 @@ jQuery.extend({
// is the only cross-browser way to do this. --John
// is the only cross-browser way to do this. --John
isFunction
:
function
(
fn
)
{
isFunction
:
function
(
fn
)
{
return
!!
fn
&&
typeof
fn
!=
"string"
&&
!
fn
.
nodeName
&&
return
!!
fn
&&
typeof
fn
!=
"string"
&&
!
fn
.
nodeName
&&
typeof
fn
[
0
]
==
"undefined"
&&
/function/i
.
test
(
fn
+
""
);
fn
.
constructor
!=
Array
&&
/function/i
.
test
(
fn
+
""
);
},
},
// check if an element is in a XML document
// check if an element is in a XML document
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment