Re: [JSMentors] Best approach to OOP in JavaScript

2011-09-27 Thread Xavier MONTILLET
Apparently, they think about standardizing __ptoto__ too. Sent from my smartphone. On Sep 27, 2011 8:14 PM, "Xavier MONTILLET" wrote: > Btw, they're speaking of adding an new proto operator <| that could be > used with an object before and a litteral after and it would set the > litteral's protot

Re: [JSMentors] self executing function

2011-09-27 Thread Xavier MONTILLET
(function(){ //code })(); is the module pattern and is widely used. If you assign the result to a variable, there is no problem: var result = (function(){ //code })(); But if you don't, since files are often gathered for perfomance, if a file with something like that is before yours: (f

Re: [JSMentors] self executing function

2011-09-27 Thread Rob Griffiths
Hi Pete The two are in fact !function(){}() and (function(){})() The first can be used where your immediately invoked function expression doesn't return anything However the second can be used when you do with to return a value. Ben Alman's article may help you more. http://benalman.com/news/2

[JSMentors] self executing function

2011-09-27 Thread Pete
Hi, could anyone explain me the difference in using "!" or ";" in front of "function() {}();" thanks pete //seen at https://github.com/twitter/bootstrap/blob/master/js/bootstrap-alerts.js !function( $ ){ }( window.jQuery || window.ender ); //seen at https://github.com/madrobby

Re: [JSMentors] Best approach to OOP in JavaScript

2011-09-27 Thread Xavier MONTILLET
Btw, they're speaking of adding an new proto operator <| that could be used with an object before and a litteral after and it would set the litteral's prototype to the object. The problem with __proto__ is performance so <| will only work at object creation. You can't change the prototype of an exi

Re: [JSMentors] Best approach to OOP in JavaScript

2011-09-27 Thread Nick Morgan
On 27 September 2011 17:25, Lasse Reichstein wrote: > Also, when doing pure object-based design, you have to keep your categories > clear. Your Human and Man objects are clearly prototype objects, not > instance objects. They are meant to be inherited, not used directly. The > object you create w

[JSMentors] Re: Best approach to OOP in JavaScript

2011-09-27 Thread Jarek Foksa
According to this benchmark Object.create() is ~10 times slower than constructor functions on Chrome: http://jsperf.com/object-create-vs-crockford-vs-jorge-vs-constructor/26 Will an average app written with Object.create() be noticeably slower than the same app implemented with constructor functio

Re: [JSMentors] Best approach to OOP in JavaScript

2011-09-27 Thread David Marrs
On Tue, Sep 27, 2011 at 2:01 PM, Jarek Foksa wrote: > After some searching on the web, I stubled upon this message by > Brendan Eich: > https://mail.mozilla.org/pipermail/es-discuss/2011-February/012893.html > > Why does he want to remove __proto__ from Spidermonkey? I would rather > expect an ef

Re: [JSMentors] Better JSON traversal?

2011-09-27 Thread Dean Landolt
On Tue, Sep 27, 2011 at 10:18 AM, Jan Frühwacht wrote: > So indexing just moves the processing time to the beginning instead of > runtime object resolution and creates the flattest hierachy. > Is that right ? > Pretty much. I wouldn't say it *moves* the processing time to the beginning -- indexin

Re: [JSMentors] Better JSON traversal?

2011-09-27 Thread Jan Frühwacht
So indexing just moves the processing time to the beginning instead of runtime object resolution and creates the flattest hierachy. Is that right ? 2011/9/20 Rey Bango > Very cool. Thanks! :D > > > On Tue, Sep 20, 2011 at 12:09 PM, Dean Landolt wrote: > >> >> >> On Tue, Sep 20, 2011 at 9:55 AM,

[JSMentors] Re: Best approach to OOP in JavaScript

2011-09-27 Thread Jarek Foksa
How about this code, it uses Object.extend() instead of __proto__ for creating inheritance chain as described here: http://yehudakatz.com/2011/08/12/understanding-prototypes-in-javascript/ Looks pretty clean, though I'm not sure whether iterating over object properties won't slow down the code. Co

Re: [JSMentors] Best approach to OOP in JavaScript

2011-09-27 Thread Jarek Foksa
After some searching on the web, I stubled upon this message by Brendan Eich: https://mail.mozilla.org/pipermail/es-discuss/2011-February/012893.html Why does he want to remove __proto__ from Spidermonkey? I would rather expect an effort to standarize this useful property. Is there any standard r

Re: [JSMentors] Best approach to OOP in JavaScript

2011-09-27 Thread Peter van der Zee
On Tue, Sep 27, 2011 at 2:38 PM, Jarek Foksa wrote: > Why nobody does the inheritance like in the sample code below? Besides > the fact that __proto__ is non-standard and Object.create() is pretty > new, is there anything wrong with this code? For some reason it feels Besides that, nope. - peter

[JSMentors] Best approach to OOP in JavaScript

2011-09-27 Thread Jarek Foksa
I'm a bit confused about what is the right way to write object oriented code in JS. The majority of the projects on the web are using constructor functions coupled with prototypes, but I don't really understand why. Why nobody does the inheritance like in the sample code below? Besides the fact th

[JSMentors] Re: URL Blocker

2011-09-27 Thread Kumar
I would disagree with few things you mentioned. But sticking to the point, we are not talking about one DOM api, but all others like insertBefore and replaceChild. It is obvious that HTMLBodyElement extends HTMLElement and that inherits Element (and that inherits Object). The obvious implementatio

Re: [JSMentors] Re: URL Blocker

2011-09-27 Thread Lasse Reichstein
On Tue, Sep 27, 2011 at 6:13 AM, Cheney, Austin < austin.che...@travelocity.com> wrote: > No, appendChild is a DOM property that adds a pointer from one DOM node, a > parent, to another DOM node, a child. While a DOM node is represented in > JavaScript as an object literal pointers, however, are