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

2011-03-21 Thread Lasse Reichstein
On Sun, 20 Mar 2011 15:04:27 +0100, Jason Mulligan jason.mulli...@avoidwork.com wrote: return ((arg % 2) === 0) ? true : false; Just on general principle, the ? true : false part is completely unnecessary. The condition is already a boolean, so just do: return ((arg %

[JSMentors] Re: Introductions

2011-03-21 Thread Mike Trinder
On Mar 19, 5:47 pm, Jared Hirsch ja...@jaredhirsch.com wrote: I've only written JS to run inside browsers and server-side V8. I'd love it if you could share some examples of the differences between native and host objects :-) Well, my original statement was borne mostly out of frustration

[JSMentors] DOM Node Tree manipulation patterns?

2011-03-21 Thread Will Rock
Hey all, I'm playing around with contentEditable and I'm current working with styling (bold, italic, etc...) of the current selection (window.getSelection()). Now, I know I can do this via document.execCommand (in certain browsers), but I'd like to implement my own method. I can easily apply a

[JSMentors] accessing global variable in a callback

2011-03-21 Thread tim perkis
I'm misunderstanding something about global scope in javascript, and node.js in particular. I have a global data structure which drives my entire (small) node.js app. For debugging, I wanted to be able to send a message to the app that triggers dumping this struct to the console. code is like:

Re: [JSMentors] accessing global variable in a callback

2011-03-21 Thread Peter van der Zee
On Sun, Mar 20, 2011 at 9:26 PM, tim perkis t...@perkis.com wrote: Is there something I'm not understanding about global scope? Maybe the fact that there is none :) Not in node in the classic sense anyways. I guess I would monkey patch your own object for debugging and just assign whatever

Re: [JSMentors] accessing global variable in a callback

2011-03-21 Thread Poetro
In Node.js the global object is called `global`, but you rarely need to interact with it, and in most cases you shouldn't. If you need something that is modularized make your own module, and include it with the `require` function. And on initialization of that module you may send it your from the

Re: [JSMentors] Re: Extending built-in objects with properties

2011-03-21 Thread Jarek Foksa
Oh, and you don't have to take my word for it: Kangax, What’s wrong with extending the DOM, 5 April 2010 http://perfectionkills.com/whats-wrong-with-extending-the-dom/ Very nice article and discussion beneath it, thanks for pointing this out. But I still think that extending

Re: [JSMentors] Re: Extending built-in objects with properties

2011-03-21 Thread Poetro
2011/3/21 Jarek Foksa ja...@kiwi-themes.com: Oh, and you don't have to take my word for it: Kangax, What’s wrong with extending the DOM, 5 April 2010 http://perfectionkills.com/whats-wrong-with-extending-the-dom/ Very nice article and discussion beneath it, thanks for pointing this out.

[JSMentors] Post/repo on small something to help with checking for object conformance

2011-03-21 Thread npup
Hi, I wrote a little utility to help out with checking status of objects. More specifically, checking their conformance with a signature that you provide along with the check. It is partly meant to help out when expecting quacker objects to be sent as parameters to your functions - you know, to

Re: [JSMentors] Post/repo on small something to help with checking for object conformance

2011-03-21 Thread Nick Morgan
As I've said in your comments section, I think this is a really good idea. We need to get away from the old instanceof/constructor thing, and fully embrace duck-typing. This looks a nice way of formalising that. On 21 March 2011 14:33, npup petter.env...@gmail.com wrote: Hi, I wrote a little

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

2011-03-21 Thread georgecalm
Hi Peter, You're right, I didn't give much context did I... Here it is: My primary goal is to make the code above testable. I've gotten into a habit of externalizing instantiable dependencies (e.g var window = new Window(); var house = new House(window);). This helps when unit- testing