Closed Bug 277429 Opened 20 years ago Closed 20 years ago

javascript: loosing all methods of inherited native objects

Categories

(SeaMonkey :: General, defect)

x86
Windows XP
defect
Not set
normal

Tracking

(Not tracked)

RESOLVED INVALID

People

(Reporter: kohl, Unassigned)

Details

Attachments

(1 file)

e.g.: 
function Table(row,col) {
  this.base = Array; // Date
  this.base(col);
  ....
the resulting constructor Table has no Array (Date,..) specific method, e.g. no
length
You are not inheriting from the Date, Array Objects properly. You might find
<http://bclary.com/2004/09/26/boot-camp-javascript#Introduction_to_Objects> helpful.

-> INVALID
Status: UNCONFIRMED → RESOLVED
Closed: 20 years ago
Resolution: --- → INVALID
Summary: javascript: loosing all methods of inherited native objects → javascript: loosing all methods of inherited native objects
thanks for the "bclary" reference! not uncommented wrong/misleading examples,
but a glance of an understandable concept; additionally an answer to getters and
setters ("deprecated/recommended"),
and no more surprises to expect like output of { [native code] } for
xy.toSource() for a self written xy and loosing getters
> Which examples did you find incorrect or inadequately commented?

Not yours!!!
Sorry, maybe I've taken wrong words.

Some months ago, I'd had found some javascript examples, e.g. belonging to SVG
use (mostly Mozilla SVG), or valuable documents like XFLY.
I don't know exactly where, but in one or some of these papers I've found the
deprecated/wrong/old methods, which I'd used - I didn't find better information
for the state of art until your paper
I've found the cause of my usage of 
  this.base = Constructor; this.base(...)
This is, as I see after reading the document given in the answer, of course a
strange idea, Constructor.call or .apply don't create the unnecessary
"this.base" or even an additional "this.base2".
And I've read the passage "You need still to explicitely set up the prototype to
ensure dynamic inheritance" in the same paper as "when you are needing only
static inheritance, this is not necessary".
Source of this misleading hints is the "Core JavaScript Guide 1.5" from
Netscape, last update 28.9.2000

The standard constructors for Mozilla, called in that manner, are indeed not
working as I'd expected. There are also some restrictions due to then syntax,
but arrays may indeed be inherited and a part of the expected implications of
inherited arrays - partly masking of arrays! - is working (to be used with
caution because of the potential of language changes).
An example beside of the use of sparse matrices:

// masking a line of a projection matrix ... 
function Projection(mask) { // mask: 0 .. x, 1 .. y, 2 .. z
  if (mask) this[mask] = [0,0,0,0];
  this.project = affine;
}

Projection.prototype = new Array;

Projection.prototype[0] = [ 1,0,0,0 ];
Projection.prototype[1] = [ 0,0,1,0 ], 
Projection.prototype[2] = [ 0,1,0,0 ], 
Projection.prototype[3] = [ 0,0,0,1 ];

Projection.prototype.name   = "Projection";
// for (var ee= 0; ee < 7; ee++) Projection.prototype[ee] = ee * Math.sin(ee);
// dynamically changeable


You need to log in before you can comment on or make changes to this bug.

Attachment

General

Creator:
Created:
Updated:
Size: