Kean and especially Michael,
Thank you for sharing this very useful knowledge bit ! This must be
the most insightful thread in a while :)
Alexandre
On Wed, Dec 31, 2008 at 8:49 AM, Kean shenan...@gmail.com wrote:
Alexandre,
Another word of caution. Do choose your labels carefully. Avoid
Good point. In fact, 'new' isn't just a reserved word, it's an operator!
Regarding these method calls:
a.new(); // still fails in ie
a.class(); // still fails in ie
If you have to, you can call methods with illegal names by using [] notation
instead of . notation:
a['new']();
// YUI compressor won't compress if you have no quotes on keywords
float: function() {
alert(float);
},
int: function(){
alert(int);
}
}
a.float();
a.int();
int and float are reserved words as well. Technically, you are
On Dec 31, 2008, at 7:51 AM, pete higgins wrote:
int and float are reserved words as well. Technically, you are
supposed to quote all keys (JSON), but in reality you only need to
quote the reserved ones. default gets me every time.
Hi Pete,
I know you already know this, but just for
Karl,
I think you mean other than alpha or underscore (just to
nit/completeness ;) ) Always safer to go with fully quoted, though I
tend to avoid it myself unless necessary.
var foo = { 1bar : is valid, 2bar:is not, _iam:valid too,
this-is:valid also }
of course, we should mention accessing
On Dec 31, 2008, at 9:42 AM, pete higgins wrote:
On Wed, Dec 31, 2008 at 9:34 AM, Karl Swedberg
k...@englishrules.com wrote:
Hi Pete,
I know you already know this, but just for completeness I thought I
should
mention that you need to quote not only reserved-word keys but also
keys
and, yeah, I usually put in bare keys (sans quotes) unless necessary, too.
Not sure why. I guess I just like the clean look.
Yah, they just seem to be wasted bytes, huh?
One thing to note, and the only reason I try to force myself to use
the quotes is for portability. If the data is really
friends, following what i learned in this post i'm busy rewriting my object.
i have a specific question.
in my old code i would have something like:
var datascape = new Object();
datascape.ini = function(){
datascape.availableWidth = $(window).width();
}
};
can i rewrite it like this:
var
On Dec 29, 11:14 pm, Angel Marquez angel.marq...@gmail.com wrote:
they are contemplating hiring me!
I already sent it back and thought I'd post it here to see the response.
I just noticed this thread, and I have to say... I would be wary of
any potential employer presenting these kinds of
// YUI compressor won't compress if you have no
// quotes on keywords
float: function() {
alert(float);
},
int: function(){
alert(int);
}
}
a.float();
a.int();
int and float are reserved words as
And $, don't forget $ :-)
var obj = { $foo_bar$: 'howdy' };
-Mike
_
From: Karl Swedberg
On Dec 31, 2008, at 7:51 AM, pete higgins wrote:
int and float are reserved words as well. Technically, you are
supposed to quote all keys (JSON), but in reality you only need to
quote the
From: pete higgins
About anything can be a key in JS. (DomNodes can't, though
btw, but functions objects etc)
No, that isn't true, sorry.
Object keys in JavaScript are strings only, nothing else.
var bar = { a:b, c:d };
var bar2 = [1,2,3,4];
var foo = {};
foo[bar] = baz;
foo[bar2] =
About anything can be a key in JS. (DomNodes can't, though
btw, but functions objects etc)
No, that isn't true, sorry.
No need to be sorry.
I stand corrected. My misunderstanding of this nuance stems from
having never noticed the toString function defined here ...
toString:
On 30 Dez., 08:45, Alexandre Plennevaux aplennev...@gmail.com
wrote:
JavaScript enclosures?
i think it has to do with encapsulating your code inside a function so
that all vars are inside the function's scope, so not cluttering the
global namespace.
This, to avoid memory leak.
Are you
Klaus, you got me: frankly i have no real idea what is the purpose
of enclosure.
That's abstract art to me. i just read in several places that it's
good to use it, so i trust my sources, do it and move on. Not that i'm
proud of it, but, to use a metaphor, one does not need to know the
internals
Klaus is right,
Here's an article about closure causing leaks
http://www.javascriptkit.com/javatutors/closuresleak/index.shtml
On Dec 30, 4:38 am, Alexandre Plennevaux aplennev...@gmail.com
wrote:
Klaus, you got me: frankly i have no real idea what is the purpose
of enclosure.
That's
A good reason why closure is used
http://yuiblog.com/blog/2006/06/01/global-domination/
On Dec 30, 1:04 pm, Kean shenan...@gmail.com wrote:
Klaus is right,
Here's an article about closure causing
leakshttp://www.javascriptkit.com/javatutors/closuresleak/index.shtml
On Dec 30, 4:38 am,
wair, you're all scarrying me:
i often do things like this:
var datascape = new Object();
datascape.el = $('#datascape');
datascape.ini = function(){
datascape.el.click(function(){
dothis();
dothat();
});
}
is this pattern causing a potential memory leak
According to Microsoft, closures are the cause of memory leaks. This
is of course deeply wrong, but it leads to Microsoft giving very bad
advice to programmers on how to cope with Microsoft's bugs.
http://javascript.crockford.com/memory/leak.html
This article seems to be a lot more reasonable,
Just a nitpick.
Don't do this
var datascape = new Object();
var datascape2 = new Array();
Instead
var datascape = {};
var datascape2 = [];
On Dec 30, 1:27 pm, Alexandre Plennevaux aplennev...@gmail.com
wrote:
wair, you're all scarrying me:
i often do things like this:
var datascape = new
I think Michael wanted to point out that they're called 'closures' and
not 'enclosures'. For a hiring questionnary that's not very bright.
Another one: there's no such thing as a Javascript class. You can
have class-like instantiation, but strictly we're speaking about
objects, constructors and
See, that is the kind of feedback I was interested in. I sell my self short
and thought I saw some inconsistencies and discrepancies; but, was unsure.
I appreciate everyones feedback.
Thank you,
Angel
You got it, that's exactly what I was getting at, Ricardo. I assumed that
they actually meant closures, but who knows, they could have even been
referring to something else.
Actually I've been getting a kick out of (or getting annoyed by, I'm not
sure which) the terminology that's come into use
On Dec 31, 2008, at 12:47 AM, Michael Geary wrote:
They use in context like this: You need to achieve Function
Closure. Not the way I would word it, but at least I can understand
what
they mean. :-)
That's pretty funny. Sounds like something you might find in a self-
help book. :-)
why? It's just a shorthand, isn't it ? does it affect the computer
resources in any manner ?
On Wed, Dec 31, 2008 at 3:12 AM, Kean shenan...@gmail.com wrote:
Just a nitpick.
Don't do this
var datascape = new Object();
var datascape2 = new Array();
Instead
var datascape = {};
var
As for JS, saving bytes is totally a good thing.
On Dec 30, 10:53 pm, Alexandre Plennevaux aplennev...@gmail.com
wrote:
why? It's just a shorthand, isn't it ? does it affect the computer
resources in any manner ?
On Wed, Dec 31, 2008 at 3:12 AM, Kean shenan...@gmail.com wrote:
Just a
They create exactly the same result.
The object or array literal is likely to be a tiny bit faster than the new
Object/Array, because it avoids a name lookup (or several name lookups if
you're inside a nested function). But of course even if it is faster, it
would make a difference only if
Alexandre,
Another word of caution. Do choose your labels carefully. Avoid
keywords.
Adding quotes to keyword labels ensure compatibility with YUI
compressor.
var a = {
// new without quotes produce error in ie
new: function() {
alert(new);
},
//
Here's a few answers.
2. XmlHTTPrequest object, returns XHR request as obj or string, YUI
callback augments object, jQuery callback augments string
4. http://www.json.org/
5. block / inline
6.
assume allLayer is array of layer1 and layer2
YAHOO.util.Dom.setStyle(allLayer, opacity, 66%);
Huh?
Are you writing these questions, or you've been given them to answer and
you're looking for help answering them, or what?
If you're looking for the answers, is the potential employer contemplating
hiring you, or hiring the rest of us in this group? :-)
The list seems to be first and
yea, I got those ones.
thanks
On Mon, Dec 29, 2008 at 8:55 PM, Kean shenan...@gmail.com wrote:
Here's a few answers.
2. XmlHTTPrequest object, returns XHR request as obj or string, YUI
callback augments object, jQuery callback augments string
4. http://www.json.org/
5. block / inline
Concur with Michael, that's why I'd answered the obvious ones.
haha
they are contemplating hiring me!
I already sent it back and thought I'd post it here to see the response.
Appreciate it.
I think my answers were correct..
The first argument method is 'void', correct?
On Mon, Dec 29, 2008 at 9:07 PM, Michael Geary m...@mg.to wrote:
Huh?
Are you
JavaScript enclosures?
i think it has to do with encapsulating your code inside a function so
that all vars are inside the function's scope, so not cluttering the
global namespace.
This, to avoid memory leak.
something the likes:
(function(){
/// your code goes here
})(jquery);
I have
34 matches
Mail list logo