#3330 closed feature (fixed)
jQuery.typeof and jQuery.isEmpty Utilities
Reported by: | projectatomic | Owned by: | |
---|---|---|---|
Priority: | major | Milestone: | 1.4.3 |
Component: | core | Version: | 1.4.2 |
Keywords: | Cc: | ||
Blocked by: | Blocking: |
Description
One of the best aspects of jQuery is its light weight. I have really taken advantage of some of its built in Utilities such as jQuery.extend() and jQuery.map(). I am definitely against bloated software, but I find myself writing these functions time and again. They are pretty utilitarian and not too huge. Just a suggestion (code borrowed from Crockford's Remedial JavaScript)
- A better typeof function that actually returns 'array' for an array instead of 'object':
function typeOf(value) {
var s = typeof value; if (s === 'object') {
if (value) {
if (typeof value.length === 'number' &&
!(value.propertyIsEnumerable('length')) && typeof value.splice === 'function') {
s = 'array';
}
} else {
s = 'null';
}
} return s;
}
- A simple isEmpty function that returns a boolean:
function isEmpty(o) {
var i, v; if (typeOf(o) === 'object') {
for (i in o) {
v = o[i]; if (v !== undefined && typeOf(v) !== 'function') {
return false;
}
}
} return true;
}
Change History (2)
comment:1 Changed 13 years ago by
comment:2 Changed 12 years ago by
Milestone: | 1.3 → 1.4.3 |
---|---|
Resolution: | → fixed |
Status: | new → closed |
Version: | 1.2.6 → 1.4.2 |
isEmpty already exists - landing jQuery.type() http://github.com/jquery/jquery/commit/94f35d05199ec1634d9c8c60d10f298f260056bd
Anyone have a patch for this?