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

2011-05-25 Thread Jeremy Solarz
Thx for clarification! On Wed, May 25, 2011 at 4:14 PM, Poetro wrote: > > Hi guys, > > > > the first test in > > > > http://jsperf.com/prototype-members-vs-instance-members/6 > > > > is written like this: > > > > function MyClass1() { > > > > > > this._privateAttribute = 42; > > > > } > > > >

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

2011-05-25 Thread Poetro
> Hi guys, > > the first test in > > http://jsperf.com/prototype-members-vs-instance-members/6 > > is written like this: > > function MyClass1() { > > >   this._privateAttribute = 42; > > } > > > MyClass1.prototype = { > > >   _privateMethod: function() { > > >     return this._privateAttribute; >

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

2011-05-25 Thread Jeremy Solarz
Hi guys, the first test in http://jsperf.com/prototype-members-vs-instance-members/6 is written like this: function MyClass1() { this._privateAttribute = 42; } MyClass1.prototype = { _privateMethod: function() { return this._privateAttribute; }, publicMethod: function() {

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

2011-05-24 Thread Tio Oscar
I do: Var MyClass = function() { This.initialize.apply(this, arguments); } MyClass.staticMethod = function () { } MyClass.prototype = { PrivValue: null, Initialize: function (param) { Console.log("hello world"); }, PrivMethod: function(param) {

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

2011-05-24 Thread vapour
I prefer to the under style: var templateManager = (function () { var templates = {}; function supplant(str, params){ for (var prop in params) { str = str.split('{' + prop + '}').join(params[prop]); } return str; } return { render: funct

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

2011-04-29 Thread Bemi Faison
@Scott Doy! I didn't take time to see that. Thanks. @Gildas Thanks for expanding the test! It's very interesting to note how protyped instances and global methods both perform well. I'd assume, it's because both optimize memory usage, while inlined and composed objects require more memory pointe

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

2011-04-29 Thread Gildas
On Apr 29, 4:43 pm, Bemi Faison wrote: > @Gildas > > I think that's incredibly useful information. Thanks for the link! > > What about "building" an object? I don't know whether to call it > object-composition or the object-factory pattern, but don't libraries > use this to provide advanced object

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

2011-04-29 Thread Scott Sauyet
Bemi Faison wrote: > Could you add something like this to your tests? JSPerf lets you do this yourself. -- Scott -- 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: ht

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

2011-04-29 Thread Bemi Faison
@Gildas I think that's incredibly useful information. Thanks for the link! What about "building" an object? I don't know whether to call it object-composition or the object-factory pattern, but don't libraries use this to provide advanced object-inheritance features? I've always felt this would b

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

2011-04-28 Thread Gildas
This thread gave me the idea to compare performances of 2 ways of creating objects : - by adding methods to prototype object - by adding methods directly to the new object (but function definitions are not copied and parsed for each new object) The majority of modern browsers give better results w

[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) { >