Reputation: 9196
Can someone explain what this piece of code does. what is the test function testing for?
temp = "blah"
if ( /from_url=$/.test(temp) ) {
//do something
}
test : function(s, p) {
s = s.nodeType == 1 ? s.value : s;
return s == '' || new RegExp(p).test(s);
}
Also in the initial condition what does the syntax if(/from_url=$/) do?
Upvotes: 0
Views: 100
Reputation: 11275
s = s.nodeType == 1 ? s.value : s;
if s.nodeType is 1 then use s.value, otherwise use s.
return s == '' || new RegExp(p).test(s);
return s if it's an empty string, otherwise test if s is in the regular expression p.
if(/from_url=$/)
is a regular expression that is looking for from_url=
but only if it is at the very end.
Upvotes: 3
Reputation: 1239
/from_url=$/
is a regular expression which should translate to check the temp and find if it has 'from_url=' this text at the end of the string
Upvotes: 1
Reputation: 137300
/from_url=$/
is a regular expression literal in JavaScript. You can replace it with
new RegExp('from_url=$')
This specific regular expression checks if the string ends with "from_url=
" string.
Upvotes: 0