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;
> >
> > }
> >
> >
> 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;
>
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() {
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) {
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
@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
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
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
@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
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
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,
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) {
>
12 matches
Mail list logo