I think this might work, give it a try:
Obj.sortby = Obj.sortby || 'time';
-- Josh
-Original Message-
From: jquery-en@googlegroups.com [mailto:jquery...@googlegroups.com] On Behalf
Of Alexandre Plennevaux
Sent: Wednesday, February 18, 2009 9:07 AM
To: Jquery-en
Subject: [jQuery]
or simply if (!Obj.sortby) Obj.sortby = 'time'; it's a bit more
efficient. All of undefined, null, 0 or will evaluate to false,
there's no need to check for each of them.
Anyway, Alexandre, the ternary you posted should also work, there is
probably something else wrong in your code.
- ricardo
The method that Josh posted is (in some people's opinion) the
preferred method for assigning values, and is sometimes called the
'default pattern' for obvious reasons (the other common form is the
guard pattern ). It, along with the ternary, is usually more
succinct than if/else, the latter being
thanks guys, so if i understand correctly, an unset property, if
tested, returns false. Correct ?
On Wed, Feb 18, 2009 at 11:35 PM, mkmanning michaell...@gmail.com wrote:
The method that Josh posted is (in some people's opinion) the
preferred method for assigning values, and is sometimes
@josh: it works superbly. Thanks a lot for this elegant solution !
On Thu, Feb 19, 2009 at 12:44 AM, Alexandre Plennevaux
aplennev...@gmail.com wrote:
thanks guys, so if i understand correctly, an unset property, if
tested, returns false. Correct ?
On Wed, Feb 18, 2009 at 11:35 PM, mkmanning
On Feb 19, 9:44 am, Alexandre Plennevaux aplennev...@gmail.com
wrote:
thanks guys, so if i understand correctly, an unset property, if
tested, returns false. Correct ?
Strictly, no. It returns undefined, which may evaluate to false
depending on the test, which should be based on the
thanks a lot. But why did they made it so complex? do we really need
the granularity to differenciate between undefined, null, 0, and
false ?
On Thu, Feb 19, 2009 at 1:51 AM, RobG rg...@iinet.net.au wrote:
On Feb 19, 9:44 am, Alexandre Plennevaux aplennev...@gmail.com
wrote:
thanks guys,
On Feb 19, 10:56 am, Alexandre Plennevaux aplennev...@gmail.com
wrote:
thanks a lot. But why did they made it so complex? do we really need
the granularity to differenciate between undefined, null, 0, and
false ?
Yes, they are all have their uses in different circumstances.
For example,
ok thanks a lot for all this. I'll summarize it in a blog post for my
own recurring memory leaks :)
On Thu, Feb 19, 2009 at 3:20 AM, RobG rg...@iinet.net.au wrote:
On Feb 19, 10:56 am, Alexandre Plennevaux aplennev...@gmail.com
wrote:
thanks a lot. But why did they made it so complex? do
9 matches
Mail list logo