473,785 Members | 2,761 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Does anybody undesrstand this line of code from prototype.js

Hello, this sentence is from the Ajax.Request.pr ototype function in
prototype.js:

this.url += (this.url.match (/\?/) ? '&' : '?') + parameters;

I understand what it does but I don't know how does "/\?/" work. Would
it be the same as "this.url.match ('?')" ?

- What is each slash for?
- Is "\?" an escape character?

Can anybody help me?

Carlos from Barcelona.

Apr 19 '06 #1
2 1466
eq******@gmail. com wrote:
Hello, this sentence is from the Ajax.Request.pr ototype function in
prototype.js:

this.url += (this.url.match (/\?/) ? '&' : '?') + parameters;

I understand what it does but I don't know how does "/\?/" work. Would
it be the same as "this.url.match ('?')" ?

- What is each slash for?
- Is "\?" an escape character?

Can anybody help me?

Carlos from Barcelona.


Hi Carlos

Its a regular expression, broken down

/ is the start of the expression

\? match a question mark anywhere in the url

/ is the end of the expresssion.

the \ is an escape character because ? on its own means something
else entirely.

Regular expressions are a very powerful tool for matching patterns
in strings. There is plenty of info on the web about them and
one here.

http://www.sitepoint.com/article/exp...s-javascript/2

HTH

Chris

Apr 19 '06 #2
eq******@gmail. com said the following on 4/19/2006 7:16 AM:
Hello, this sentence is from the Ajax.Request.pr ototype function in
prototype.js:
It's a line of code, not a sentence. But another reason why I don't use
prototype.js
this.url += (this.url.match (/\?/) ? '&' : '?') + parameters;

I understand what it does but I don't know how does "/\?/" work. Would
it be the same as "this.url.match ('?')" ?
Close. It uses the ternary operator to see if it has a ? in the url and
then appends parameters accordingly.
- What is each slash for?
It is part of the Regular Expression that match is using.
- Is "\?" an escape character?


Yes.

--
Randy
comp.lang.javas cript FAQ - http://jibbering.com/faq & newsgroup weekly
Javascript Best Practices - http://www.JavascriptToolbox.com/bestpractices/
Apr 19 '06 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
2223
by: vakap | last post by:
function show() { var s = '' ; for (var i = 0; i<arguments.length; s += '\n'+arguments) ; typeof(window) != 'undefined' ? window.alert(s) : WScript.Echo(s) ; } function f(){} show('delete(f):',delete(f)) ; // false g = function(){} ;
6
2207
by: deejaybags | last post by:
could someone please have a look at this and tell me why it segfaults. i am confused as all hell! stringman.h void load_string(char *newString); char * remove_string(); char * remove_upper_string(); char * remove_lower_string(); (i havent written the removes yet);
14
4863
by: Anoop | last post by:
Hi, I am new to this newsgroup and need help in the following questions. 1. I am workin' on a GUI application. Does C# provides Layout Managers the way Java does to design GUI? I know that it can be done using the designer but I intentionally don't want to use that. The one reason is that you cannot change the code generated by the designer. The other could be that you have more free hand and control to design your GUI. 2....
89
6079
by: Cuthbert | last post by:
After compiling the source code with gcc v.4.1.1, I got a warning message: "/tmp/ccixzSIL.o: In function 'main';ex.c: (.text+0x9a): warning: the 'gets' function is dangerous and should not be used." Could anybody tell me why gets() function is dangerous?? Thank you very much. Cuthbert
9
3098
by: pamelafluente | last post by:
Hi, I was "studying" the famous (public code) BusyBox. I see the instruction: var busyBox = new BusyBox as in var busyBox = new BusyBox("BusyBox1", "busyBox", 4, "gears_ani_", ".gif", 125, 147, 206)
14
3495
by: webEater | last post by:
I have a problem, it's not browser specific, and I don't get a solution. I have an (X)HTML document, I show you a part of it: .... <!--<div class="pad">--> <div id="eventImages"><img src="" id="eventImage0" class="eventImage"><img src="" id="eventImage1" class="eventImage"></div>
92
6258
by: Heinrich Pumpernickel | last post by:
what does this warning mean ? #include <stdio.h> int main() { long l = 100; printf("l is %li\n", l * 10L);
3
1892
by: kj | last post by:
OK, here's another construct I've run into in the jQuery source that I can't figure out. It looks like this: return new jQuery.prototype.init( selector, context ); So basically, as far as I can tell, the returned value has the form new obj.prototype.method( args ); (In addition, FWIW, the function jQuery.prototype.init has several
19
1738
by: Prisoner at War | last post by:
Okay, Folks, I guess my real burning concern all along is a "high-level" one: just how does JavaScript interact with CSS? Right now, my newbie self only knows JavaScript and CSS to *co- exist*...but I'm beginning to get the sense that they actually interact -- or, perhaps more precisely, JavaScript acts upon CSS...but how, exactly??
0
9645
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
10336
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10155
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10095
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9953
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
8978
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7502
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6741
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5513
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.