🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: adobe.scripting.indesign
Article #1873

Re: pls explain abt prototype

#1873
From: Harbs
Date: Wed, 21 Jan 2009 06:51
32 lines
1967 bytes
Yes. I wasn't thinking of default values...

I'm very wary of prototyping standard classes. I once created a 
prototype function on the js Object class, and it caused some 
very_difficult_to_track_down bugs in another script which happened to be 
running in the same engine. Since then, I've stayed far away from 
prototyping anything besides my own private classes...

Generally, there's no need to create a prototype method to accomplish 
the goal. Simon's example is functionally equivalent to:

function Contains(array,a)
      {
        for (var r = 0; r < array.length; r++)
          {
            if (array[r] == a) { return true; }
          }
        return false;
      }
and you just write: if(Contains(array,a)){do something...}

There's actually an advantage to not use prototyping in Simon's example: My construct can be used on any object which has a length property (like strings or collections).

Dirk's example can be done in a similar way.

This is the construct that I generally use. I think it's a lot safer (albeit slghtly harder to read) than polluting the public classes...

I don't think there's any performance gain by using prototypes here.

-- 
Harbs
http://www.in-tools.com
Technical Details
Message-ID: <DDF269DF388271AD269C94A88990C450@in.webcrossing.la2eafNXanI>
Path: arc1-ca.pugleaf.net!g2news1.google.com!news1.google.com!newshub.sdsu.edu!webcrossing
References: <59b78cbc.-1@webcrossing.la2eafNXanI> <59b78cbc.0@webcrossing.la2eafNXanI> <859B1F6D0F3E1FCF27AD0D04CAE16809@in.webcrossing.la2eafNXanI>

Show Full Headers
Complete Article Headers
X-Google-Thread: f939a,ba3fc2ccca9a708d
X-Google-Attributes: gidf939a,domainid0,public,usenet
X-Google-Language: ENGLISH,ASCII-7-bit
From: Harbs
Path: arc1-ca.pugleaf.net!g2news1.google.com!news1.google.com!newshub.sdsu.edu!webcrossing
Newsgroups: adobe.scripting.indesign
Subject: Re: pls explain abt prototype
Message-ID: <DDF269DF388271AD269C94A88990C450@in.webcrossing.la2eafNXanI>
Date: Tue, 20 Jan 2009 22:51:33 -0800
References: <59b78cbc.-1@webcrossing.la2eafNXanI> <59b78cbc.0@webcrossing.la2eafNXanI> <859B1F6D0F3E1FCF27AD0D04CAE16809@in.webcrossing.la2eafNXanI>
Lines: 37
User-Agent: Thunderbird 2.0.0.14 (Macintosh/20080421)
MIME-Version: 1.0
Content-Type: text/plain; charset="ISO-8859-1"
Content-Transfer-Encoding: 8bit