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

Post March 7th, 2007, 6:07 am

Hello Javascript experts

Do you know what is the use of
Code: [ Download ] [ Select ]
str = (this != window)?this:str;

in a function. str is the arg passed to that function.
  • Anonymous
  • Bot
  • No Avatar
  • Joined: 25 Feb 2008
  • Posts: ?
  • Loc: Ozzuland
  • Status: Online

Post March 7th, 2007, 6:07 am

  • joebert
  • Weathered
  • Genius
  • User avatar
  • Joined: Feb 10, 2004
  • Posts: 11874
  • Loc: Clearwater, FL
  • Status: Offline

Post March 7th, 2007, 6:35 am

Why yes, yes I am.

Post March 7th, 2007, 6:40 am

you beat me to his 2nd multiple topic post.

Post March 7th, 2007, 6:42 am

Oh!
Question is not about operator.
My question is about why there is check for this == window or string.
Where is the possibility of this== window and not arg. passed.

Thanks!
  • joebert
  • Weathered
  • Genius
  • User avatar
  • Joined: Feb 10, 2004
  • Posts: 11874
  • Loc: Clearwater, FL
  • Status: Offline

Post March 7th, 2007, 9:13 am

Oh.

str is passed in you say ?

Code: [ Download ] [ Select ]
function mystery(str){
  str = (this != window) ? this : str;
}

elm.onclick = mystery;
mystery(elm);
  1. function mystery(str){
  2.   str = (this != window) ? this : str;
  3. }
  4. elm.onclick = mystery;
  5. mystery(elm);


Hmmm.

Looks like a method designed to either be assigned as an event handler, or used from the window namespace with the target object as the argument.
Why yes, yes I am.

Post March 8th, 2007, 1:20 am

Thank You joebert!
This time you tried hard.

Now your answer has something I was looking for. (window namespace...)

It was designed for working with prototype also. May be that is the reason for that line.
So does it mean when I have to write function that can be assigned to prototype then I have to use this line:
str = (this != window) ? this : str;


regards
Satya Prakash
  • joebert
  • Weathered
  • Genius
  • User avatar
  • Joined: Feb 10, 2004
  • Posts: 11874
  • Loc: Clearwater, FL
  • Status: Offline

Post March 8th, 2007, 1:55 am

It's odd looking to me, I'd like to see it being used, kinda looks like an ancestry walker or somthing.

As of now I don't see any good uses for it.
Why yes, yes I am.

Post March 11th, 2007, 11:39 pm

You can use this link to see usage:
http://www.faqts.com/knowledge_base/vie ... 1678/fid/1

If you like to reply again for this topic, I will certainly read that in hope that I will get some more info.
  • joebert
  • Weathered
  • Genius
  • User avatar
  • Joined: Feb 10, 2004
  • Posts: 11874
  • Loc: Clearwater, FL
  • Status: Offline

Post March 12th, 2007, 12:54 am

I still don't see a good reason to use that line.

I'd rather see it defined as a prototype of the String object from the get-go.
Why yes, yes I am.

Post Information

  • Total Posts in this topic: 9 posts
  • Users browsing this forum: jammer2552 and 126 guests
  • You cannot post new topics in this forum
  • You cannot reply to topics in this forum
  • You cannot edit your posts in this forum
  • You cannot delete your posts in this forum
  • You cannot post attachments in this forum
 
 

© Unmelted Enterprises 1998-2009. Driven by phpBB © 2001-2009 phpBB Group.