473,386 Members | 1,786 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

javascript experts : str = (this != window)?this:str;

Hello experts
Do you know what is the use of
Expand|Select|Wrap|Line Numbers
  1. str = (this != window)?this:str;
in a function.
str is arg passed to that function.


regards
Satya Prakash
Mar 7 '07 #1
3 1378
acoder
16,027 Expert Mod 8TB
? and : is a ternary operator short for if-then-else, see link.

In your example, this is a reference to the current object, if it's not window, then set the str variable to the current object, otherwise set it to the str value that is passed.

It's short for:
Expand|Select|Wrap|Line Numbers
  1. if (this != window) {
  2.  str = this;
  3. } else {
  4.     str = str;
  5. }
Mar 7 '07 #2
? and : is a ternary operator short for if-then-else, see link.

In your example, this is a reference to the current object, if it's not window, then set the str variable to the current object, otherwise set it to the str value that is passed.

It's short for:
Expand|Select|Wrap|Line Numbers
  1. if (this != window) {
  2.  str = this;
  3. } else {
  4.     str = str;
  5. }
Operator I know, but next paragraph is useful for me.
I did not get why it is checking. The function was for trimming the space.

Is it anything to do with using the function in prototype.
Mar 12 '07 #3
acoder
16,027 Expert Mod 8TB
Give the whole function then.
Mar 12 '07 #4

Sign in to post your reply or Sign up for a free account.

Similar topics

3
by: Tuxtrax | last post by:
Hi all. I have need of assistance on something that should be very simple, and is driving me absolutely batty. This is a code snippet from a short program that downloads news headers via...
3
by: hazz | last post by:
will the third ctor in this class call the first two or just the null ctor? public class B { public B() { ... } public B(string str) {.....} public B(Token tkn, string str, int int_var) :...
3
by: Mike P | last post by:
I have a method that I use for Javascript validation (see below). What I want to do is change the alert title, buttons, icon etc. Does anybody know the correct syntax to do this? private void...
5
by: turnbiz | last post by:
Hi, Could anyone help me decrypting this script: <script type='text/javascript'>...
2
by: thirunavukarasukm | last post by:
Hai.... "i want used confirm in javascript in code behind" i am used confirm button ,,,in code behind. if the confirm button worked the function is return the true...
6
by: Mike P | last post by:
I am trying to build up some text in a stringbuilder and then use javascript to show it with an alert box. Here is my attempt to show it in an alert box : string str = ""; str += "<script...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
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,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
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...

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.