On Feb 1, 2:33 pm, Garrett Smith <[email protected]> wrote:
> On 1/31/11, RobG <[email protected]> wrote:
>
> > On Feb 1, 3:32 am, Anton Podviaznikov <[email protected]> wrote:
>
> [....]\
>
> >> 2. I extended native FIle and FileError objects. Is it normal? Is it
> >> good style? How you will do this?
>
> Extending a host object is a bad idea.
>
> > It is generally not a good idea to extend built-in objects. Is there a
> > significant advantage to doing it? If not, don't.
>
> And even worse to extend or modify a host object, wichi is apparently
> what the OP is doing (and I have n[t read that code...).

Yes, good point. The "native" bit threw me onto the wrong track.
Extending host objects is very much a bad idea, e.g. from fs.js:

  Object.defineProperty(File.prototype,'shortName', ...);

One of the objectives of the W3C specifications is to be language
agnostic, so host objects are not required to implement an ECMAScript
compliant inheritance model (and have been shown not to), they only
need to provide a API compliant with the specification.

At the very least the above should be something like:

  if (Object.isExtensible && Object.isExtensible(File.prototype)) {
    ...
  }

But just don't do it.

BTW, is there any *real* advantage to:

  var o = {};
  Object.defineProperty(o, 'doStuff', {value: function(){...}});

over:

  var o = {};
  o.doStuff = function(){...};

given that you shouldn't be adding properties to objects you don't own
or don't know will allow it?

--
Rob

-- 
To view archived discussions from the original JSMentors Mailman list: 
http://www.mail-archive.com/[email protected]/

To search via a non-Google archive, visit here: 
http://www.mail-archive.com/[email protected]/

To unsubscribe from this group, send email to
[email protected]

Reply via email to