hiding divs

R

Randy Webb

GregS said:
Load it in Mozilla, watch the loading bar. It hangs. Also, view the
screenshot that rf posted.

http://validator.w3.org/check?uri=http://www.worcsnet.com/mainLayout

lists 20 errors to start with.

[1] I think the developers of IAB Studio need to spend a lot more
time *lurking* and *asking questions* on c.l.js, c.i.w.a.html,
c.i.w.a.stylesheets and c.i.w.a.site-design before they go offering
advice to others, especially since their software is churning out pages.



Andrew Thompson, I'm one of the developers of IAB Studio. I do not
think you ever used IAB Studio, and your remarks seem to be quite
rude, offending and pointless; I do not see any reason for that. It's
quite strange to me that you post such comments without even knowing
what IAB Studio is. Given this, your advice is just not credible.

One does not have to use a product to see the outcome of that product.

I have never used DreamWeaver nor Frontpage but I can tell you, from
experience of seeing its code, that it does *not* produce good, quality
code. It may well be easy to use for the developer but for creating
quality code, they both suck.

But given that you are defending your own product without any more than
a rant at one who posts contradictions to you, your advice/comments are
just not credible.
 
R

Randy Webb

GregS said:
Randy, thanks you for your comments.

I think that not always "incorrect" HTML is incorrect. For example,
this parser of yours seems to find error even if there are no errors.
For example:

Line 10, column 62: general entity "pageNum" not defined and no
default entity

....lling="auto" src="main?AC=showPage&pageNum=10003"

The problem comes from error 1, which is always the first error to fix.
The lack of a DTD causes the validator to guess. It guessed HTML4.01
Transitional, when if they Frameset DTD had been present, it would have
parsed it differently.
This is a perfectly correct URL. If you look at the source, you will
see that it is a simple frameset. I think this parser is not the most
trustworthy.

See Above.
I'm sure that you know that sometimes developers do things like that:

<DIV myattr1="blablabal" myattr2="blablabla" >, which makes perfect
sense in the context of your web application, but is not "perfect"
HTML. Or you can use custom tags, which are not "perfect" HTML, but it
still does not make it wrong - again, in the context of your
application.

If I want my own custom tags, I don't use HTML. But, I do use my own
tags, and my own attributes in PHP code. But I also have it remove them
before its sent to the browser. They are there for my own search/replace
routines so I have them removed so that what is sent to the browser is
valid HTML. Then, if it doesn't render properly in the browser, then I
know its not my code so I know where to look next.
The loading bar is actually a FF/NN/Mozilla bug. If you create many
dynamic iframes, then sometimes FF does not stop 'loading' the page,
although it's already been loaded. IE handles this situation a lot
better.

Personally, I wouldn't use IE as a base reference for quality of a page.

Internet Explorer is the most lax environment on the web to try to
script in. Just because something "works" in IE doesn't make it good
code, it just means a crappy browser will execute it:

myID.property

IE handles that a lot better than any other browser. But, to make it
work in any browser that supports it, use
document.getElementById('myID').property and it works in any of them.

I also turn a bad eye to any site that tells me:

"Inet Application Builder requires Internet Explorer 5.5+ or Netscape
v6.2+."

That alone indicates browser detection based on userAgent strings and
they are about as predictable as predicting the farts on an island of
bean eaters.
And as for the picture rf posted - yes, if you change default font
sizes in FireFox (like, setting the minimum font size), that's exactly
how the page will look. But half of all web sites will look the same;
I'm not sure what point RF was trying to make. It may be more of a
design issue - if I say style="font-size:12", it means I want it this
way.

And if I tell my browser "I want larger text", then thats the way I want
it. In the end, its the user who is in control of the browser, not the
page author.

In my IE6, with my chosen settings, I get much the same image/page that
rf got. Except that I don't have colors. I have the font sizes disabled
because I sit about 3 feet from the monitor and want larger font sizes.

http://allmyfaqs.com/faq.pl?AnySizeDesign

And I'd like to mention that developing web applications (actually RIA
apps) in IAB Studio is a bit different than in other HTML editors; it
has very little to do with scripting HTML (or HTML in general). HTML
in IAB pages serves more like data for the runtime engine, which
creates actual controls... So while I understand your concern about
invalid HTML, it is not really applicable to IAB Studio. Anyway,
thanks for your remarks.

Welcome.
 
M

Michael Winter

GregS wrote:
[snip]
Line 10, column 62: general entity "pageNum" not defined and no
default entity
....lling="auto" src="main?AC=showPage&pageNum=10003"

The problem comes from error 1, which is always the first error to fix.
The lack of a DTD causes the validator to guess. It guessed HTML4.01
Transitional, when if they Frameset DTD had been present, it would have
parsed it differently.

The error would still remain. The ampersand (&), as you know, begins a
character reference. The validator complains because &pageNum; [1] is not
a valid reference in any DTD (unless you wrote your own).

As character references can occur in attribute values, literal ampersands
should be encoded with the &amp; character reference.

This is explained in the previous error, in both the error message itself
and the link, "Ampersands in URLs".

Mike


[1] The terminating semicolon isn't actually necessary according to SGML
parsing rules. I'm not sure what the specifics of those rules are, but I
expect that non-alphanumeric characters can't be part of a reference.
 
G

GregS

Randy Webb said:
In my IE6, with my chosen settings, I get much the same image/page that
rf got. Except that I don't have colors. I have the font sizes disabled
because I sit about 3 feet from the monitor and want larger font sizes.

you are right and the site should honor this kind of setup
 
G

GregS

Richard Cornford said:
"advanced JS techniques"; not an easy claim to quantify. One person's
advanced technique is old-hat to another, and a bad idea to a third. A
Agree. I guess the same goes for OO design.
HttpRequest - 'class'. First the data objects - QueryType - and -
DataRequestType - are clearly bound with the 'class' in their
employment, but both are created as global variables. OO design would
Wrong assumtion.These objects are used as enumerations.They have
nothing to do with classes. Yes they have to be global because they
are used in multiple pages.

In fact, this wrong assumtion makes your code not usable at all.


So one implementation pattern that provides all of the encapsulation
called for the OO, and avoids the inefficiencies in the original might
go:-
var HttpRequest = (fucntion(){
var QueryType = { SqlQuery:0};
var DataRequestType = {
SQL : 0,
... //etc.
Wrong again. QueryType and DataRequestType are supposed
to be global. See Above.

neither make any use of the fact that they are inner functions, a

They do. It is a lot more readable to me than
using constr.prototype.prepareDataRequest = function(targetFrameId

except that imho the original code seems to be simpler to read and
understand.
Apart from that, it does the same thing as your suggestion, and it can
in fact be made abit more efficient than yours (see below)
Indeed it is questionable whether it makes any sensefor - prepareFormDOM - to > be a separate function as it
is always called form - prepareDataRequest - and unavailable to any other code.

Yes it does. This function does one thing - creates a
dynamic form, and it makes a lot of sense to have it
as a separate function.

Overall, I do not really see any significant changes
from the original code except for a couple very
minor changes. Also your changes are just incorrect given that you
assumed things, which are not true in this particular web application.


The original code can be optimized a bit, provided that, instead of

if(typeof
(this.constructor.prototype.PrototypeFinishedHttpRequest)

== 'undefined'){

this.constructor.prototype.prepareDataRequest=prepareDataRequest;

this.constructor.prototype.PrototypeFinishedHttpRequest=true;
};

function prepareDataRequest

I can have

if(typeof
(this.constructor.prototype.PrototypeFinishedHttpRequest)

== 'undefined'){

this.constructor.prototype.prepareDataRequest=prepareDataRequest;

this.constructor.prototype.PrototypeFinishedHttpRequest=true;

function prepareDataRequest (){
}

};

So that indeed the function object will be created
only once, no matter how many objects you create.
 
R

Richard Cornford

GregS said:
Richard Cornford wrote:
Wrong assumtion.These objects are used as enumerations.They
have nothing to do with classes. Yes they have to be global
because they are used in multiple pages.

Fair enough, if you are using them in multiple classes then they will
need to be global.
In fact, this wrong assumtion makes your code not usable
at all.

You don't see how to correct that then?
Wrong again.

Surly not 'again', as these are the same objects as mentioned above.
QueryType and DataRequestType are supposed
to be global. See Above.

So bump them up a scope, nothing else needs to change.

No they don't.
It is a lot more readable to me than
using constr.prototype.prepareDataRequest =
function(targetFrameId

except that imho the original code seems to be
simpler to read and understand.

Maybe, code is certainly easier to understand when you are familiar with
javascript as a language.
Apart from that, it does the same thing as your suggestion,
and it can in fact be made abit more efficient than yours
(see below)

I think you will find that it cannot be more efficient, you might find
an alternative with equivalent efficiency but your original was very
poor in that regard, and the following suggestion is not going to help
that.

The original code can be optimized a bit, provided that,
instead of

if(typeof
(this.constructor.prototype.PrototypeFinishedHttpRequest)
== 'undefined'){

this.constructor.prototype.prepareDataRequest=prepareDataRequest;

this.constructor.prototype.PrototypeFinishedHttpRequest=true;
};

function prepareDataRequest

I can have

if(typeof
(this.constructor.prototype.PrototypeFinishedHttpRequest)
== 'undefined'){

this.constructor.prototype.prepareDataRequest=prepareDataRequest;

this.constructor.prototype.PrototypeFinishedHttpRequest=true;

function prepareDataRequest (){
}

};

So that indeed the function object will be created
only once, no matter how many objects you create.

So what do you imagine that will do? A conditional function declaration?
There is no such thing in javascript. Indeed the ECMA 262 (3rd edition)
production rules forbid a function declaration from appearing within a
block statement, which leaves the only possible interpretation of the
code as a function expression with the optional identifier, and that
expression would be evaluated after the assignment so even if ECMA 262
allowed the optional identifier to appear in the containing scope (which
it does not [1]) the preceding assignment would still not have assigned
a reference to a function object.

There are numerous faulty implementations that disregard the syntax
error of placing a function declaration within a block statement, but
they still follow the normal variable instantiation procedure upon
entering an execution context so the declarations are not conditional
and so the corresponding function objects are still going to be created
with each and every object instantiation when only the first created
will ever be used.

Richard.

[1] The Gecko bug of leaking the identifiers of function expressions
with optional identifiers into the containing scope can give the
illusion of conditional function declarations, but that is not what is
really happening, and relying on an implementation bug in one
environment is not a route to cross-browser code.
 
G

GregS

Richard Cornford said:
<snip>
There is no such thing in javascript. Indeed the ECMA 262 (3rd edition)
production rules forbid a function declaration from appearing within a
block statement,
Probably you are referring to this document:
http://www.ecma-international.org/publications/files/ECMA-ST/Ecma-262.pdf
Could you point out which paragraph prohibits that?
[1] The Gecko bug of leaking the identifiers of function expressions
with optional identifiers into the containing scope can give the
illusion of conditional function declarations, but that is not what is
really happening, and relying on an implementation bug in one
environment is not a route to cross-browser code.
Well, the following code works fine in IE, Netscape, Mozilla, FireFox
and Opera.
Do they all have the same bug? I've read that Opera/FF/etc developers
said they follow the standards. So if this code works fine in all
these browsers - does it make it valid JS code? I guess so.


<SCRIPT>

function Customer (id, startValue){

this.id=id;
this.startValue=startValue || 1000;

if(typeof (this.constructor.prototype.a1) =='undefined'){

//get customer id
function getId (){
return this.id;
};

//calculate something
function calc (){
return this.startValue * 100;
};

this.constructor.prototype.getId=getId;
this.constructor.prototype.calc=calc;
this.constructor.prototype.a1=true;

//change the id for the first object being created
this.id = "Generated ID. Will it change for all objects or
for the first only?"

alert ('We will only see this alert once.');

};
};

var aa = new Customer ('Customer 1', 100);
alert ('First Customer Created');

var aa1 = new Customer ('Customer 2', 200);
alert ('Second Customer Created');

var aa2 = new Customer ('Customer 3');
alert ('Third Customer Created');

alert ('id for object aa:' + aa.getId () + " Calc:" + aa.calc ());
alert ('id for object aa1:' + aa1.getId () + " Calc:" + aa1.calc ());
alert ('id for object aa2:' + aa2.getId () + " Calc:" + aa2.calc ());

</SCRIPT>




Granted, your approach may (or may not be) faster. But I guess the
only way to compare which code is more efficient is to actually run
it.
So can you post your own version of the Customer class (complete
implementation, so that I can just copy and paste it), let's say
Customer1? Then we can run a simple test script, something like that
(simply create 100000 Customer objects):

var t1 = new Date ().getTime ();
for (var i = 0; i < 100000; i ++){
new Customer (); //my version
// or new Customer1 (); //your version
};
var t2 = new Date ().getTime ();

alert (t2 - t1)




And it should tell, which approach is more efficient.


Greg
 
R

Richard Cornford

GregS said:
Richard Cornford wrote:
Probably you are referring to this document:
... /Ecma-262.pdf
Could you point out which paragraph prohibits that?

Section 14: the production rules for SourceElement, Section 13: the
production rules for FunctionDeclaration and FunctionBody, and Section
12.1: Block statements and StatementList; seem most pertinent.
[1] The Gecko bug of leaking the identifiers of function
expressions with optional identifiers into the containing
scope can give the illusion of conditional function
declarations, but that is not what is really happening, and
relying on an implementation bug in one environment is
not a route to cross-browser code.
Well, the following code works fine in IE, Netscape,
Mozilla, FireFox and Opera.

More functions rather than works. But their behaviour is neither
identical nor consistent, and none of them are actually doing what you
seem to be assuming them to be doing.
Do they all have the same bug?

The three execution environments named all have bugs in this area, but
they don't have the same bug.
I've read that Opera/FF/etc developers said they follow
the standards. So if this code works fine in all these
browsers - does it make it valid JS code? I guess so.

Mozilla/Gecko is often cited as the most standards compliant browser,
but that doesn't mean that what Mozilla/Gecko does defines the standards
it attempts to implement; that type of thinking is the wrong way around.
<SCRIPT>

function Customer (id, startValue){

this.id=id;
this.startValue=startValue || 1000;

if(typeof (this.constructor.prototype.a1) =='undefined'){

//get customer id
function getId (){
return this.id;
};

//calculate something
function calc (){
return this.startValue * 100;
};

this.constructor.prototype.getId=getId;
this.constructor.prototype.calc=calc;
this.constructor.prototype.a1=true;

//change the id for the first object being created
this.id = "Generated ID. Will it change for all"+
" objects or for the first only?"

alert ('We will only see this alert once.');
};

If you want to see Opera and IE not doing what you seem think they are
doing try adding this alert at this point:-

alert ('typeof calc = '+(typeof calc));

- and while Mozilla/Firefox may seem to be doing conditional function
declarations it is in fact exhibiting its bug in the handling of the
optional identifiers on FunctionExpressions.
Granted, your approach may (or may not be) faster.
But I guess the only way to compare which code is more
efficient is to actually run it.

Not creating unneeded function objects with each object instantiation is
bound to be faster than doing so, there is no need to time the code to
see that, it is self-evident.
So can you post your own version of the Customer class
(complete implementation, so that I can just copy and
paste it), let's say Customer1? Then we can run a simple
test script, something like that (simply create 100000
Customer objects):
And it should tell, which approach is more efficient.

Superfluous, but if it will discourage you from burying your head in the
sand:-

function Customer1(id, startValue){
this.id = id;
this.startValue = (startValue || 1000);
}
Customer1.prototype.getId = function(){
return this.id;
};
Customer1.prototype.calc = function(){
return (this.startValue * 100);
};

Commenting out the - this.id - assignment and the alert within the if
statement in your version, mine appears to be better than two to four
times faster under your test procedure (depending on the execution
environment).

Richard.
 
M

Michael Winter

Richard Cornford wrote:
[snip]
Indeed the ECMA 262 (3rd edition) production rules forbid a function
declaration from appearing within a block statement,
[snip]

Could you point out which paragraph prohibits that?

It's not in the prose, but it's clearly specified in the grammar (well,
assuming formal grammar is "clear" to you). Here are probably the most
relevant parts, rewritten in a BNF style for brevity and clarity:

Program :
SourceElement+

SourceElement :
Statement
FunctionDeclaration

Block :
{ Statement* }

Notice the clear distinction between a statement and a function
declaration, and that blocks may only contain the former (if anything).
Well, the following code works fine in IE, Netscape, Mozilla, FireFox
and Opera.

I could only be bothered to experiment briefly in Opera, but your code
"works" because it seems to be treated as

function Customer(...) {
function getId() {...}
function calc() {...}

if(...) {
...
}
}

You can see that by placing alert(calc + '\n' + getId); after the if
statement.
Do they all have the same bug?

I would venture that they're trying to cope with invalid code just like
they do with malformed HTML. However in both cases, don't take advantage
of the leniency: write valid code.
I've read that Opera/FF/etc developers said they follow the standards.

They do, but they can only suffer so many complaints that boil down to:
"Why won't your browser properly interpret this poorly written crap?"
That, and the odd bug here and there, will result in some deviation from
the standards, usually in the form a more lax interpretation.

In any case, it is the standard that you should follow, not a particular
implementation of it.
So if this code works fine in all these browsers - does it make it valid
JS code?

Not in the least.

[snip]

Mike
 
G

GregS

You can see that by placing alert(calc + '\n' + getId); after the if
statement.
Yes, that appears to be the case.

That, and the odd bug here and there, will result in some deviation from
the standards, usually in the form a more lax interpretation.
In any case, it is the standard that you should follow, not a particular
implementation of it.
I agree. But how come this code works (not "works") in ie, gecko
borwsers and opera? Does that mean that they do not really support the
standard? I do not care if it's a bug, more lax interpretation, or
whatever. If it's the standard, should not the browser treat this code
as an error?

Greg

PS This particular code was not meant to discuss 'dynamic' functions.
It was meant to discuss whether or not a function can be declared in a
block.
 
G

GregS

times faster under your test procedure (depending on the execution
environment).

Sure this code will. One can come up with a lot of different ways to
achieve the same.

What I meant, in your first post you offered another implementation of
the original code, which looked something like that and included
function constr:

var HttpRequest = (fucntion(){
....
function constr(id, docObj){
this.id = id;
this.docObj=docObj;
}

constr.prototype.prepareDataRequest = function(targetFrameId,
queryType, requestType, params){
.... whatever
}



I'd like to see your version of the Customer class written in this
fashion.


Greg
 
M

Michael Winter

[snip]
But how come this code works (not "works") in ie, gecko borwsers and
opera? Does that mean that they do not really support the standard?

Of course they do. It would be classed as an "extension" of the language:

"A conforming implementation of ECMAScript must provide and support
all the types, values, objects, properties, functions, and program
syntax and semantics described in this specification.
...
A conforming implementation of ECMAScript is permitted to support
program and regular expression syntax not described in this
specification. [...]" (Section 2 - Conformance, ECMA-262)

Still, don't do it.
I do not care if it's a bug, more lax interpretation, or whatever. If
it's the standard, should not the browser treat this code as an error?

In my opinion, yes, but I said in my last post that browser vendors are
bombarded by requests for dubious "features" because a user has
encountered a badly-authored document.

You should see some of the Mozilla support forums or Bugzilla. Rather than
placing the blame squarely with the author, users think that the browser
is at fault and demand stupid additions.
PS This particular code was not meant to discuss 'dynamic' functions. It
was meant to discuss whether or not a function can be declared in a
block.

No. If you're attempting to improve efficiency by evaluating a function
only when necessary, use a function expression. I haven't looked at the
original source, but there are probably plenty of other ways, too.

Mike
 
G

GregS

Michael Winter said:
No. If you're attempting to improve efficiency by evaluating a function
only when necessary, use a function expression. I haven't looked at the

Fair enough. What do you think of using eval function, something like


<SCRIPT>

function cc (id){

this.id = id;

if (id == 1){
eval ("function bb () {alert (this.id);};
this.constructor.prototype.func=bb;");
}

if (typeof bb == 'function')
alert (id + ":" + bb)

}

new cc (2); //alert will not pop up. bb not there?
new cc (1).func (); //alert will pop up. bb is there?


</SCRIPT>

It appears to conditionally declare function bb (I checked this code
in ie/gecko/opera). Does this violate the standard? I do not think I'd
use it anyway, I think it makes code harder to understand/maintain.

Greg
 
R

Richard Cornford

GregS said:
Sure this code will. One can come up with a lot of
different ways to achieve the same.

What I meant, in your first post you offered another
implementation of the original code, which looked
something like that and included function constr:

var HttpRequest = (fucntion(){
....
function constr(id, docObj){
this.id = id;
this.docObj=docObj;
}

constr.prototype.prepareDataRequest =
function(targetFrameId, queryType, requestType, params){
.... whatever
}

I'd like to see your version of the Customer class written
in this fashion.

Your - Customer - object does not warrant that style of implementation.
Wrapping the creation of the constructor, and the assignment of method
to the prototype, in an inline function expression can serve no purpose
with such an object. Though as your test method is only interested in
the time taken for the creation of an object instance you would not see
any different results if the constructor was created within a function
expression executed inline. (The overhead with that technique is a
one-time cost when the function expression is executed, but that
one-time cost justifies not using the technique when it is not providing
any benefit in return for that cost.)

The factor that suggested that style of implementation with the
original - HttpRequest - was the fact that the - prepareFormDOM -
seemed conceptually private static, and the closure produced by creating
(and configuring) the constructor with the inline execution of a
function expression allows that function to be both private (in the
sense of not being accessible to code outside of the function
expression) and available to all instances of the 'class'.

Richard.
 
M

Michael Winter

[snip]
What do you think of using eval function, something like
[snip]

eval ("function bb () {alert (this.id);};"
+ "this.constructor.prototype.func=bb;");

I'm quite speechless, and not in a good way.

[snip]
It appears to conditionally declare function bb (I checked this code in
ie/gecko/opera).

But so would

this.constructor.prototype.func = function() {alert(this.id);};
Does this violate the standard?

No, just common sense.

[snip]

I must say I'm still not sure why this is all necessary. Why wouldn't a
Customer object have getId and calc methods initially?

Mike
 
G

GregS

Michael Winter said:
I must say I'm still not sure why this is all necessary. Why wouldn't a
Customer object have getId and calc methods initially?

You are right. I was just trying to see how this kind of code can be
optimized a bit;

function Customer(...) {

function getId() {...}

if(typeof this.constructor.prototype.done == 'undefined') {
this.constructor.prototype.getId=getID;
this.constructor.prototype.done=1;
}
}
}

as Richard pointed out, upon each Customer object creation, a function
object will be created for getId function declaration; I guess
realistically it may not a problem when only one or just a few are
created; so I tried to see if it can be created dynamically (I mean
using function declarations, not function expressions) and if there
will be any advantages.

It appears though that the 'fastest' approach is this -|

function Customer(...) {

this.constructor.prototype.getId=function () {};

}
}


Greg
 
M

Michael Winter

[snip]
It appears though that the 'fastest' approach is this -|
function Customer(...) {

this.constructor.prototype.getId=function () {};

}
}

Assuming the data members are public, the fastest would be

function Customer(id, ...) {
this.id = id;
}
Customer.prototype.getId = function() {return this.id;};

as creation of the function is a one-time-only cost. If you want to make
the members private, then

function Customer(id, ...) {
this.getId = function() {return id;};
}

would be. The function would be created anew with every new object, but
it's the only realistic choice.

Mike
 
R

Richard Cornford

You might also question the need to have a - getId - method at all, when
the - id - property it returns (unaltered) is already public and can be
read (and set) directly from the object.
You are right. I was just trying to see how this kind of
code can be optimized a bit;

function Customer(...) {

function getId() {...}

if(typeof this.constructor.prototype.done == 'undefined') {
this.constructor.prototype.getId=getID;
this.constructor.prototype.done=1;
}
}
}

There is plenty of potential for optimising the test in addition to the
actions following from the passing of the test. The evaluation of the -
if - expression currently involves; resolving a property accessor,
applying the unary - typeof - operator to the result, comparing the
result of that with a string literal and finally type-converting that
result to boolean to make the - if - decision (the last being a trivial
operation as the result of the comparison is already boolean). Given
that the property accessor resolves to a value that is either undefined
or (in this example) numeric one, applying the NOT operator to the
property accessor as the - if - expression:-

if(!this.constructor.prototype.done){
...
}

- produce identical results, as the unary NOT operator will type-convert
the value to boolean and invert it, resulting in false for numeric 1 and
true for undefined, without the need for any other operations. The
overall result will be considerably faster (string comparison being
quite an involved operation when the strings being tested actually do
match, and the typeof algorithm specifying an additional safety check
that NOT does not use (and is irrelevant in this context).

Additionally, the property accessor - this.constructor.prototype.done -
will take longer to resolve than - this.done -, and in the context of
its use in the opening lines of a constructor the two will be reporting
the same value (- this - having inherited its - done - value (if any)
from the constructor's prototype).

But it is questionable whether the - done - flag is required at all as
applying a type-converting test (or even the less efficient - typeof -
test) to any of the methods assigned will produce equivalent result, and
avoid the need to assign a - done - value:

if(!this.getId){
this.constructor.prototype.getId = getId;
}

Repeatedly resolving - this.constructor.prototype - during the
assignments will also become burdensome if it needs to be done more than
a couple of times. The prototype object reference could be cached to a
local variable to reduce that overhead.

However, overall it has got to be fastest and simplest to configure the
constructor's prototype unconditionally outside of the constructor.
Other object designs, those implementing Douglas Crockford's private
instance members technique, attempting multiple inheritance or
implementing common interfaces shared by many classes/subclasses, might
necessitate alternative inheritance patterns (mostly forms of object
augmentation) but the simple javascript objects benefit most from
following the standard javascript prototype inheritance pattern.
as Richard pointed out, upon each Customer object creation,
a function object will be created for getId function
declaration;

Didn't I also mention the overhead in repeating the tests on each object
instantiation?
I guess realistically it may not a problem when only
one or just a few are created; so I tried to see if it
can be created dynamically (I mean using function declarations,
not function expressions) and if there will be any advantages.

It appears though that the 'fastest' approach is this -|

function Customer(...) {

this.constructor.prototype.getId=function () {};

}
}

'fastest'?

Richard.
 
M

Michael Winter

On Sun, 28 Nov 2004 11:18:30 -0000, Richard Cornford

[snip]
You might also question the need to have a - getId - method at all, when
the - id - property it returns (unaltered) is already public and can be
read (and set) directly from the object.

That hadn't escaped my attention. It was just a minor point in the face of
the eval call.

[snip]

Mike
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,774
Messages
2,569,596
Members
45,143
Latest member
SterlingLa
Top