[JSMentors] Re: Array and for/in syntax

2011-03-16 Thread RobG
On Mar 17, 10:47 am, RobG wrote: > On Mar 17, 10:40 am, RobG wrote: > [...] > > >  Try this in various browsers: > > > (function() { > [...] > > })(); > > Here's one I forgot to add: > >   // How about an array object >   var arr = []; >   arr[1] = 'one'; >   arr[0] = 'two'; >   show('Is an arr

[JSMentors] Re: Array and for/in syntax

2011-03-16 Thread RobG
On Mar 17, 10:40 am, RobG wrote: [...] > Try this in various browsers: > > (function() { [...] > })(); Here's one I forgot to add: // How about an array object var arr = []; arr[1] = 'one'; arr[0] = 'two'; show('Is an array in order?\n', arr); As expected, some return the properti

[JSMentors] Re: Array and for/in syntax

2011-03-16 Thread RobG
On Mar 17, 2:01 am, Michael Geary wrote: > On Wed, Mar 16, 2011 at 4:42 AM, Peter van der Zee wrote: > > > ... In fact, for-in is not meant to iterate an array[...] > > > (Note that the order of for-in might look stable but is not specified to be > > stable. There's some discussion to change tha

Re: [JSMentors] Re: Online JavaScript documentation.

2011-03-16 Thread Jared Hirsch
haha, no worries :-) On Wed, Mar 16, 2011 at 3:36 PM, Scott Sauyet wrote: > On Mar 16, 6:11 pm, Jared Hirsch wrote: > > On a slightly less snarky note, types are really not so > informative/useful > > in a dynamic setting like JS compared to, say, Java. > > Yes, that probably was too snarky. I

[JSMentors] Re: Array and for/in syntax

2011-03-16 Thread RobG
On Mar 16, 10:42 pm, Alex wrote: > Thank you very much for this. > > This seems to be the most "logical" explanation for "for / in " > construct. > > What I found is that Chrome does not (did not) follow that rule. Chrome is compliant with ES 3 and ES 5 in that regard. There is no reason to bel

[JSMentors] Re: Online JavaScript documentation.

2011-03-16 Thread Scott Sauyet
On Mar 16, 6:11 pm, Jared Hirsch wrote: > On a slightly less snarky note, types are really not so informative/useful > in a dynamic setting like JS compared to, say, Java. Yes, that probably was too snarky. I apologize. There was one thread recently that discussed this: http://tinyurl.com/4kfv

Re: [JSMentors] Pushing to Arrays

2011-03-16 Thread Diego Perini
On Wed, Mar 16, 2011 at 8:39 PM, Tony Wang wrote: > Oops , I find this script is too heavy for my ie8 but it's fine for firefox. > (that's just like what we know ) > > Don't click it if you are using IE. haha > > This is a smaller amount version. > http://jsfiddle.net/We9p9/3/ > > And the spe

Re: [JSMentors] Re: Online JavaScript documentation.

2011-03-16 Thread Jared Hirsch
On a slightly less snarky note, types are really not so informative/useful in a dynamic setting like JS compared to, say, Java. The docs at mozilla developer center are pretty nice, though lack the terse compactness of javadocs. JS itself has a relatively tiny API. Most libraries have a huge API

Re: [JSMentors] Pushing to Arrays

2011-03-16 Thread Tony Wang
Oops , I find this script is too heavy for my ie8 but it's fine for firefox. (that's just like what we know ) Don't click it if you are using IE. haha This is a smaller amount version. http://jsfiddle.net/We9p9/3/ And the speed still very depends on your browser implemention between n[n.len

Re: [JSMentors] Loading .js files dynamically

2011-03-16 Thread Tony Wang
I used to use this lib to handle the dynamic loading and JS dependency before. http://www.jondavis.net/techblog/post/2008/04/Javascript-Introducing-Using-%28js%29.aspx It's similar with RequireJS but it's more simple then it. 2011/3/8 Parth Bera > Hi, > > Not tested but I believe it should work

Re: [JSMentors] adding a sound clip

2011-03-16 Thread George Stagas
If you want to associate sfx with quotes you can do this: var quotes = []; quotes.push( { text: 'This is the quote text' , sfx: '/path/to/sound.ogg' } , { text: 'Another text' , sfx: '/path/to/another.ogg' } ); var quote = quotes[ Math.floor( Math.random() * quotes.length ) ]; document

Re: [JSMentors] ES5 prototype and property descriptor

2011-03-16 Thread Yusuke Suzuki
Fx4 (SpiderMonkey)'s behaviour is valid in ES5 spec. Assignment to Object Property Reference (obj.prop = "own") call [[Put]] internal method. [[Put]] checks "this value can be put" by calling [[CanPut]]. [[CanPut]] checks inherited PropertyDescriptor in 8.12.4-5, and in this case, variable "inhrer

Re: [JSMentors] Edge cases with function declarations

2011-03-16 Thread shaun
On 14/03/11 9:36 PM, Bruno Jouhier wrote: I found difference between JS engines in the way they handle code like the following: (function() { foo("m1a"); function foo(m) { alert("f1: " + m); } foo("m1b"); if (true) { foo("m2a"); function foo(m) { alert("f2: " + m); } f

Re: [JSMentors] Pushing to Arrays

2011-03-16 Thread Tony Wang
btw ,there's a interesting topic ,too. if you are doing array concat job, you could take a look for this. http://jsfiddle.net/We9p9/1/ The keypoint is , even when you are using array.push , *ary.push(1,2,3,4,5);* is still faster then *ary.push(1); ary.push(2); ary.push(3); ary.push(4); ary.push(

Re: [JSMentors] Array and for/in syntax

2011-03-16 Thread Tony Wang
For my opinion , don't use for/in for array. Because some lib will extends the Array.prototype , the function will be iterate when you doing for-in on it. for example , the following statement could explain the different between you use for-in and using index. (test it with firebug.:p ) ===

Re: [JSMentors] Feedback request: "JavaScript Engines: Under the Hood"

2011-03-16 Thread Nathan Sweet
As someone who is relatively new to web development (going on my fourth year), I've been in a somewhat new process of getting as much esoteric knowledge of JavaScript as I can get my hands on. Your presentation was very informative and contained just the right balance of solid teaching with juicy t

Re: [JSMentors] Is there no one who can challenge me?! Can you beat this?

2011-03-16 Thread Diego Perini
On Wed, Mar 16, 2011 at 6:04 PM, cancel bubble wrote: > Somewhat local newspaper site I linked to this morning following a news item > listed elsewhere (never been to their site before): > > 115 http requests > 2 meg page weight > Onload firing at a minute > > 92 JavaScript files > 1.5 megs > > ht

Re: [JSMentors] Array and for/in syntax

2011-03-16 Thread Michael Geary
On Wed, Mar 16, 2011 at 4:42 AM, Peter van der Zee wrote: > ... In fact, for-in is not meant to iterate an array but will instead > iterate all "properties" of the array. Note that an array is nothing more > than a regular object with some special stuff to it. Hence, for-in will > treat it exactly

[JSMentors] Re: Comments & critiques on a function/expression please

2011-03-16 Thread Jason Mulligan
Thanks for the second round of comments/critiques Rob, it was much more helpful this time with the added context. I'll make those changes this week when I have time. If this turns out to be a double post, I blame Google. On Mar 14, 11:39 pm, RobG wrote: > On Mar 14, 8:43 pm, Jason Mulligan > w

[JSMentors] Re: Comments & critiques on a function/expression please

2011-03-16 Thread Jason Mulligan
Thanks for the critiques, I shall make the appropriate changes. On Mar 14, 11:39 pm, RobG wrote: > On Mar 14, 8:43 pm, Jason Mulligan > wrote: > > > Hi Rob, thanks for looking. It would've been better if you had looked > > at the lib prior to making your comments, for context. > > Ok, checked ou

[JSMentors] Re: Comments & critiques on a function/expression please

2011-03-16 Thread Jason Mulligan
Hi Jared, The missing function in IE is created from the lib's init(). One thing I've noticed since doing more related (to this function) work is that IE gets an empty Array when looking for tags. I'm going to be investigating the cause tonight / tomorrow, but if you or anyone knows why that'd hel

[JSMentors] Re: Array and for/in syntax

2011-03-16 Thread Alex
Thank you very much for this. This seems to be the most "logical" explanation for "for / in " construct. What I found is that Chrome does not (did not) follow that rule. See http://code.google.com/p/chromium/issues/detail?id=883 Once again thanks for info Alex -- To view archived discussions

[JSMentors] Re: Edge cases with function declarations

2011-03-16 Thread Bruno Jouhier
Thanks. This make sense. This is not the kind of code I would write anyway, it was just an edge case I had to deal with when transforming code and I was curious. Bruno On Mar 16, 12:37 pm, Peter van der Zee wrote: > On Mon, Mar 14, 2011 at 12:06 PM, Bruno Jouhier wrote: > > Is this behavior pre

Re: [JSMentors] Array and for/in syntax

2011-03-16 Thread Matthias Reuter
Am 11.03.2011, 21:58 Uhr, schrieb Alex : I'm struggling to find something very simple. Question 1: If I have an array of integers and I use a for-in construct, do I get them in the same order they are present inside array? ex: var v = [1,2,3,4] for(var i in v){ print(i + '-->' + v[i]); }

Re: [JSMentors] Pushing to Arrays

2011-03-16 Thread Diego Perini
On Wed, Mar 16, 2011 at 12:14 PM, Rob Griffiths wrote: > >> Length should return the value of the last index + 1, so in that case >> length will return 8 > > I knew I should have checked before stating that. > > -- > Rob Griffiths > http://bytespider.eu > @bytespider > https://github.com/bytespide

Re: [JSMentors] Array and for/in syntax

2011-03-16 Thread Peter van der Zee
On Fri, Mar 11, 2011 at 9:58 PM, Alex wrote: > I'm struggling to find something very simple. > > Question 1: > If I have an array of integers and I use a for-in construct, do I get > them in the same order they are present inside array? > No. In fact, for-in is not meant to iterate an array but

Re: [JSMentors] Edge cases with function declarations

2011-03-16 Thread Peter van der Zee
On Mon, Mar 14, 2011 at 12:06 PM, Bruno Jouhier wrote: > Is this behavior precisely defined by the ECMAScript standard, or is > it left open to interpretation? > Enter Yuri or Dmitry ;) The simple answer is that yes, the ECMA standard specifically specifies that function declarations cannot occ

Re: [JSMentors] Pushing to Arrays

2011-03-16 Thread Peter van der Zee
On Thu, Mar 10, 2011 at 3:55 PM, Josi wrote: > Can somebody explain this behaviour? > > http://jsperf.com/array-push > > Why it is better to use a function instead of direct access? It's not per se, although some browsers can optimize patterns they recognize. (If you somehow mess with Array.pro

[JSMentors] Re: Online JavaScript documentation.

2011-03-16 Thread Scott Sauyet
On Mar 11, 6:39 am, stefan wrote: > I'm trying to find an on-line documentation much like this > http://krook.org/jsdom/ > but with return type for function and objects, does this exist? http://lmgtfy.com/?q=javascript+documentation+tool -- Scott -- To view archived discussions from the ori

Re: [JSMentors] Pushing to Arrays

2011-03-16 Thread Rob Griffiths
> Length should return the value of the last index + 1, so in that case > length will return 8 I knew I should have checked before stating that. -- Rob Griffiths http://bytespider.eu @bytespider https://github.com/bytespider -- To view archived discussions from

[JSMentors] Re: Pushing to Arrays

2011-03-16 Thread RobG
On Mar 16, 8:43 pm, Rob Griffiths wrote: > >  Why it is better to use a function instead of direct access? > > It's not always better. Where "better" is not defined. If the OP means faster, then in the linked tests the "best" method is evenly split between direct access and push(). The other co

Re: [JSMentors] Pushing to Arrays

2011-03-16 Thread Nick Morgan
Length should return the value of the last index + 1, so in that case length will return 8: http://jsfiddle.net/ .length is defined that way so you can safely use it to iterate over all the elements of an array with a for loop. AFAIK, `arr[arr.length] = x;` is functionally e

Re: [JSMentors] Internet Explorer Document Modes

2011-03-16 Thread gaz Heyes
On 16 March 2011 10:15, gjohnson wrote: > So my question is: what is the true difference between toggling my > Document Mode and having an actual install of the browser as far as > JavaScript goes? > ES5 methods String indexes No JS in CSS via expressions And a different DOM -- To view archive

Re: [JSMentors] Pushing to Arrays

2011-03-16 Thread Rob Griffiths
> > > Why it is better to use a function instead of direct access? > > It's not always better. Push is far better when you're not sure what the next index of your array is. for example: [87, 2, 369, , , , 42, 53] If i remember correctly .length will return 5, which means if you started adding i

[JSMentors] Edge cases with function declarations

2011-03-16 Thread Bruno Jouhier
I found difference between JS engines in the way they handle code like the following: (function() { foo("m1a"); function foo(m) { alert("f1: " + m); } foo("m1b"); if (true) { foo("m2a"); function foo(m) { alert("f2: " + m); } foo("m2b"); } foo("m3a"); function foo(m) { al

[JSMentors] Online JavaScript documentation.

2011-03-16 Thread stefan
Hello, This is my first time posting on this list so pleased to meet you all. I'm sure this has been asked before so apologies if I'm going over old ground. I'm trying to find an on-line documentation much like this http://krook.org/jsdom/ but with return type for function and objects, does this

Re: [JSMentors] A word of thanks

2011-03-16 Thread Rajesh Pillai
Wow.. Hearty Congratulations. This is what distinguishes this groups from others. Even I have learnt a lot during my short stay here and has been motivated to further my skills in JS (prior to this, I was totally a .net server side guy :)). You guys really rock!! Regards, Rajesh Pillai On Tue

[JSMentors] Array and for/in syntax

2011-03-16 Thread Alex
I will post this issue again as It seems that completelly disappeared from Group... Anyway I wanted to post my up to date research result on this - I'm struggling to find something very sim

Re: [JSMentors] adding a sound clip

2011-03-16 Thread Sai Lung Wong
If all you are looking to do is have something read out the text, then you can think about using the google Text to Speech engine. http://weston.ruter.net/projects/google-tts/ On Sun, Mar 6, 2011 at 1:37 AM, Bryce wrote: > Hello, > > I'm looking for some help on how to add a sound effect to my

Re: [JSMentors] Loading .js files dynamically

2011-03-16 Thread Parth Bera
Hi, Not tested but I believe it should work. This will cause all browsers to download files one at a time. I am sure there are other smart ways to do this so browsers can download them asynchronously. init.js function loadScript(url) { var scri

Re: [JSMentors] Re: client-side development environment

2011-03-16 Thread Jared Hirsch
Yeah, that plus the pngcrush stuff in another of Stoyan's blog posts (one of the smush.it posts) pretty much covers what SpriteMe does on the server side. On Tuesday, March 8, 2011, Ben Barber wrote: > On Tue, Mar 8, 2011 at 3:45 AM, DaveC wrote: > > > The only thing I don't have is automagic sp

Re: [JSMentors] Re: Comments & critiques on a function/expression please

2011-03-16 Thread Jared Hirsch
Hey Jason, couple thoughts quickly: - your handling of types seems a little shaky throughout. Crockford's book would probably be helpful with this, and it's a pretty quick read. - it's not immediately clear to me how this code handles the absence of getElementsByClassName in IE. Helpful? I can

[JSMentors] Array and for/in syntax

2011-03-16 Thread Alex
I'm struggling to find something very simple. Question 1: If I have an array of integers and I use a for-in construct, do I get them in the same order they are present inside array? ex: var v = [1,2,3,4] for(var i in v){ print(i + '-->' + v[i]); } is this similar to for(var i=0;i' + v[i]); }

[JSMentors] ES5 prototype and property descriptor

2011-03-16 Thread michalr
Hello, I discovered that the following ES5 code evaluates differently in FF4 than Chrome and Safari. function Ctor() {}; Object.defineProperty(Ctor.prototype, "prop", { value: "prototype", writable: false }); var obj = new Ctor(); obj.prop = "own"; alert(obj.prop + ", " + obj.has

[JSMentors] Re: What are the alternatives to "var self = this"?

2011-03-16 Thread Jorge
On Mar 3, 8:08 pm, Jarek Foksa wrote: > (...) even if default context has changed (...) NOTE TO ALL: Please *stop* calling `this` "the context", it's a misnomer. The "context" of a function/method is *not* `this`: see http://es5.github.com/#x10.3 I would suggest that a much more appropriate te

[JSMentors] Pushing to Arrays

2011-03-16 Thread Josi
Can somebody explain this behaviour? http://jsperf.com/array-push Why it is better to use a function instead of direct access? -- To view archived discussions from the original JSMentors Mailman list: http://www.mail-archive.com/jsmentors@jsmentors.com/ To search via a non-Google archive, vis

[JSMentors] Advantages & Disadvantages of Dependency-Injecting Non-Instantiable Objects

2011-03-16 Thread georgecalm
What, in your opinion, are the advantages and disadvantages of dependency-injecting non-instantiable objects in JavaScript? Some context you may want to explore are: - Unit-testing - Is it worth dep-injecting it? After all, you can overwrite the non-instantiable "static" dependency to a fake

[JSMentors] Feedback request: "JavaScript Engines: Under the Hood"

2011-03-16 Thread Jared Hirsch
Haha, me too. Loved the slides. The real question is who the audience is (vs your imagined target audience), and what their goals are in seeing a talk with the title "JS engines: under the hood." Maybe do a show of hands next time, asking who in the audience has done lisp metaprogramming or AST w