Reputation:
I am having an issue with some code...
This is the code:
(function($) {
$.fn.inc = function(url, transform, post, t) {
return this.length && url ? this.each(function() {
t = $(this);
$.ajax({
url: url,
success: function(txt, jqXHR, textStatus) {
t.html($.isFunction(transform) ? transform(txt, url) : txt);
$.isFunction(post) && post(url, jqXHR, textStatus);
}
});
}) : this;
};
$(function() {
$('[class*="inc:"]').each(function() {
var match = /inc:(\S+)/.exec(this.className || '');
if(typeOf(match[1]) != "undefined")
match && $(this).inc(unescape(match[1]));
});
});
})(jQuery);
and on line 18 it's point to this error:
ReferenceError: typeOf is not defined
if(typeOf(match[1]) != "undefined")
What's wrong with the code?
This error points to:
TypeError: a is null
**return (a.ownerDocument || a) !== n && m(a), t(a, b)**
Upvotes: 0
Views: 171
Reputation: 150020
The operator you are looking for is typeof
all in lowercase. JavaScript is case sensitive.
And note that it is an operator, not a function, so you don't need the parentheses (although they don't actually hurt).
Note also that the .exec()
method can return null
, so you need whether match
is null
before you try to use it as an array:
if (match != null && typeof match[1] != undefined)
Or just:
if (match && typeof match[1] != undefined)
But you shouldn't need to test if match[1]
is undefined
, because if match
itself is not null
then that means your regex matched including the substring match. So the following should be OK:
if (match)
$(this).inc(unescape(match[1]));
Upvotes: 1