Re: [JSMentors] Re: Bad Coercion Advice from a Guru (or why you should question everything)

2011-04-14 Thread J.R.
On Wednesday, 13 April 2011 19:37:59 UTC-3, Asen Bozhilov wrote: > > J.R.: > > > Instead of: > > if (window.ActiveXObject) { > > > > We should use: > > if (typeof window.ActiveXObject !== "undefined") { > > I would not use both approaches. I would use: > > if (typeof ActiveXObject != 'undefined

Re: [JSMentors] When to use prototype to extend a function?

2011-04-14 Thread Martin Cooper
On Thu, Apr 14, 2011 at 12:36 AM, Jason Persampieri wrote: > One other thing to keep in mind... when you define functions(methods) within > your constructor function, every new object will have their own copy of that > function definition.  When the methods are defined on the prototype, that > cod

Re: [JSMentors] keypress event in chrome

2011-04-14 Thread Jarek Foksa
I have found this presentation very helpful in understanding the difference between keydown/keypress/keyup: http://www.yuiblog.com/blog/2009/04/27/video-ppk-jsevents/ On Thu, Apr 14, 2011 at 11:08 AM, Tim Down wrote: > Yes. Use the keydown event instead. Use keypress for detecting text > input an

Re: [JSMentors] keypress event in chrome

2011-04-14 Thread Luke Smith
There's a catch. The keydown doesn't fire repetitively when you're holding arrow keys. In a way that makes sense because you're not explicitly pushing the key down (same for up). And since keypress doesn't fire (the character rule is so silly..) you have no choice but to simulate this your

[JSMentors] Re: When to use prototype to extend a function?

2011-04-14 Thread J.R.
On Thursday, 14 April 2011 10:32:53 UTC-3, J.R. wrote: > > I always ask myself when do I really need the Java-like approach in > Javascript, such as using a constructor function and the 'new' operator, and > I don't find a reasonable answer to go about writing code in that way. > > In your case,

[JSMentors] Re: When to use prototype to extend a function?

2011-04-14 Thread J.R.
On Saturday, 9 April 2011 02:46:58 UTC-3, planon wrote: > > I was reading Ben Cherry's blog post on Writing Testable Javascript > and I came across this example: > > function Templater() { > this._templates = {}; > } > > Template.prototype = { > _supplant: function(str, params) { >

Re: [JSMentors] When to use prototype to extend a function?

2011-04-14 Thread Christophe Porteneuve
IMHO, the only reason to define member functions from within the constructor is to make them what DC calls "privileged" functions: thanks to the closure, they have access to private state (local variables of the constructor function) yet are publicly accessible. Any public function that just r

Re: [JSMentors] keypress event in chrome

2011-04-14 Thread Tim Down
On 14 April 2011 10:38, Peter van der Zee wrote: > On Thu, Apr 14, 2011 at 11:25 AM, Diego Perini > wrote: >> >> On Thu, Apr 14, 2011 at 10:37 AM, Amit Agarwal wrote: >> > 'keypress' event works well in Chrome except for arrow keys. >> > >> > Any solution? >> >>  Use keydown/keyup to catch contr

Re: [JSMentors] keypress event in chrome

2011-04-14 Thread Peter van der Zee
On Thu, Apr 14, 2011 at 11:25 AM, Diego Perini wrote: > On Thu, Apr 14, 2011 at 10:37 AM, Amit Agarwal wrote: > > 'keypress' event works well in Chrome except for arrow keys. > > > > Any solution? > > Use keydown/keyup to catch control (unprintable) keystrokes as suggested > by Tim. > There's a

Re: [JSMentors] keypress event in chrome

2011-04-14 Thread Diego Perini
On Thu, Apr 14, 2011 at 10:37 AM, Amit Agarwal wrote: > 'keypress' event works well in Chrome except for arrow keys. > > Any solution? > > > -Amit > > -- > To view archived discussions from the original JSMentors Mailman list: > http://www.mail-archive.com/jsmentors@jsmentors.com/ > > To search vi

Re: [JSMentors] keypress event in chrome

2011-04-14 Thread Tim Down
On 14 April 2011 09:37, Amit Agarwal wrote: > 'keypress' event works well in Chrome except for arrow keys. > > Any solution? Yes. Use the keydown event instead. Use keypress for detecting text input and keydown/keyup for detecting general keystrokes. The following page is a very useful reference

[JSMentors] keypress event in chrome

2011-04-14 Thread Amit Agarwal
'keypress' event works well in Chrome except for *arrow keys*. Any solution? -Amit -- 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, visit here: http://www.mail-archive.com/jsmen

Re: [JSMentors] Just how efficient are JS function calls?

2011-04-14 Thread Peter van der Zee
On Thu, Apr 14, 2011 at 10:01 AM, Poetro wrote: > It just behaves totally differently from the embedded

Re: [JSMentors] Just how efficient are JS function calls?

2011-04-14 Thread Poetro
2011/4/14 Rob Steward : > Hi all, short time lurker and first time poster. > > I just started writing a new tools library, and one of the methods is > some syntactic sugar that allows you to manipulate the DOM and include > a javascript file in the head element. > > [code] > function include(files)

Re: [JSMentors] simple question

2011-04-14 Thread Jason Persampieri
On Thu, Apr 14, 2011 at 12:36 AM, Matthias Reuter wrote: > > You are trying to call the method 'get_v1' of f1. This has not been > declared either, so a TypeError is thrown. You might say, hey, I defined > that function in its prototype, so it should be taken from there. > Unfortunately, 'prototyp

Re: [JSMentors] simple question

2011-04-14 Thread Jason Persampieri
On Mon, Apr 11, 2011 at 5:53 AM, wrote: > Hello, > > I start to learn JS. > > Welcome, Sam! > ** > var f1 = function () { > this.v1 = 5; > } > Here you define a simple function. The only weird thing is the "this" references inside. Now, "this.v1" doesn't mean, "give

Re: [JSMentors] When to use prototype to extend a function?

2011-04-14 Thread Jason Persampieri
One other thing to keep in mind... when you define functions(methods) within your constructor function, every new object will have their own copy of that function definition. When the methods are defined on the prototype, that code is shared amongst all of the created objects. _jason On Thu, Apr

Re: [JSMentors] simple question

2011-04-14 Thread Matthias Reuter
** var f1 = function () { this.v1 = 5; } f1.prototype.get_v1 = function () { return this.v1; }; var f2 = new f1(); f1.v1 // return nothing f1.get_v1() // nothing f2.v1 // return 5 f2.get_v1() // return 5 ** Why f1.v1 and f1.get_v1 return no

Re: [JSMentors] simple question

2011-04-14 Thread Max Vasiliev
Because the f1 is the function. And expression 'this.v1 = 5' is in it's body. So you must execute function at least. Also, 'this' is passed to the function by callee. If you just call the function, you will not pass 'this' value, so it will refer to the global object. If you use the 'new' keyword,

Re: [JSMentors] simple question

2011-04-14 Thread Max Vasiliev
> Also, 'this' is passed to the function by callee. Oops, typo: I mean caller of course =) -- 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, visit here: http://www.mail-archive.com/

Re: [JSMentors] When to use prototype to extend a function?

2011-04-14 Thread Max Vasiliev
It's just another way to create object by some template (or prototype). Using "your" method: var o = Templater(); Using prototype: var o = new Template(); // see the 'new' keyword Usage of created object is the same: o._supplant(...); But also there's few differences in creating derived objects.