Reputation: 585
In jquery - what does (d||"").split
do?
I've got a jqtouch webapp which throws up the following error from the jquery file:
TypeError: Result of expression '(d||"").split' [undefined] is not a function.
I've tried different versions of jquery but no joy. Is it something important or can I ignore it?
edit: This is the part of the function it comes from. I'm not really sure how much to include here but its line 68 from jquery.min:
if(c.isFunction(f)){e=f;f=w}for(d=(d||"").split(" ");
edit 2: I think its got to be caused by this function here from photoswipe.js:
// Set up the options
Code.PhotoSwipe.Current.setOptions(opts);
// Tell PhotoSwipe about the photos
Code.PhotoSwipe.Current.setImages(thumbEls);
if (useEventDelegation){
/*
* Use event delegation rather than setting a click event on each
* thumb element.
*/
containerEl.addEventListener('click', function(e){
if (e.target === e.currentTarget){
return;
}
e.preventDefault();
var findNode = function(clickedEl, targetNodeName, stopAtEl){
if (Util.isNothing(clickedEl) || Util.isNothing(targetNodeName) || Util.isNothing(stopAtEl)){
return null;
}
if (clickedEl.nodeName === targetNodeName){
return clickedEl;
}
if (clickedEl === stopAtEl){
return null;
}
return findNode(clickedEl.parentNode, targetNodeName, stopAtEl);
};
var clickedEl = findNode(e.target, thumbEls[0].nodeName, e.currentTarget);
if (Util.isNothing(clickedEl)){
return;
}
showPhotoSwipe(clickedEl);
}, false);
}
else{
// Add a click event handler on each element
for (var i = 0; i < thumbEls.length; i++){
var thumbEl = thumbEls[i];
thumbEl.addEventListener('click', onClick, false);
}
}
return thumbEls;
};
swipew
Upvotes: 1
Views: 2625
Reputation: 7941
Try this code out:
var d = "matter";
(d||"").split("a"); //array: ["m","tter"]
var a = false;
(a||"").split("a"); //empty string
var c = true;
(c||"").split("a"); //type error
the || expression is a boolean check. If the left value is true (casted to boolean) then always return with the left, but if false then returns with the right.
"left"|| false == "left"
"left"||"right" == "left"
false||"right" == "right"
if d
is boolean false it will return with the ""
value, and then no error, but if the d
is boolean true (boolean true is everything which is not boolean false) but not a string it can be a TypeError
. Make sure that the d
is converted to string with .toString()
true.split("r")
will be type error, so you should use true.toString().split("r")
and it will give you ["t","ue"]
So in the common form (d||"").toString().split("r")
will be never type error
Oh i see your problem. I could help you better if you provide some source. Btw make sure you pass the right argument type to the invoked function. I dont know which fnction are you using but I am sure you pass something boolean or a number instead of a string, and i guess the problem is aboute .css() isn't it?
http://api.jquery.com/ documentation of jquery
Upvotes: 2
Reputation: 20640
It is trying to split a string into an array based on a regular expression.
It should probably be something like: split(d||"");
Why don't you edit your post to include the surrounding code?
Upvotes: 0