On Dec 25, 2010, at 9:27 PM, Michael Haufe (TNO) wrote: > On Dec 24, 9:38 pm, Garrett Smith <dhtmlkitc...@gmail.com> wrote: >> On 12/24/10, Michael Haufe (TNO) <t...@thenewobjective.com> wrote:> On Dec >> 24, 6:43 pm, Garrett Smith <dhtmlkitc...@gmail.com> wrote: >>>> The client of the API gets an interface object that has properties and >>>> methods so instanceof and constructor shouldn't matter. >> >>> instanceof is important for an interface consumer to be certain that >>> they are using the proper object: >> >> I disagree. well this is matter of preferences that should not get into a deeper discussion beyond discussing why we thing one style is better providing advantages and lessons learned by which we got to this conclusions. >> >>> function draw(group){ >>> if(group instanceof Group){ >> >> If the program is written so that group then it won't matter. The >> program can be safe enough to not have to worry about that. Example: >> >> var group = createGroup(); >> draw(group); >> >> The program would be clear what `group can do at that point. The >> constructor or prototype wouldn't matter; what matters at that point >> is what `group` can do. >> >> But if you're not sure at any point, then sure, you can use >> inferential tests like this: >> >>> if(typeof group == "object" && typeof group.method1 == "function" >>> && typeof group.method2 == "function" >>> && typeof group.method3 == "function"){ >>> //well, it looks like a group.... >> >> I don't like to see all that into an inline block. It is much less >> cluttered if the typechecking is moved into a separate function, such >> as: >> >> if(Group.isGroupLike(group)) {> group.method1(); >>> group.method2(); >>> group.method3(); //oops, its not the droid you're looking for >>> } else { >>> throw new Error("Shape Group Expected"); >>> } >>> } >> >> Better yet just get rid of the typechecking there. >> >> But, when I want to use instanceof, which is rarely, it is inside scope. > [...] > > Well, I can't disagree with a bottom up design choice. Our approaches > are just simply different. > > -- > 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: > http://www.mail-archive.com/jsmentors@googlegroups.com/ > > To unsubscribe from this group, send email to > jsmentors+unsubscr...@googlegroups.com
-- 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: http://www.mail-archive.com/jsmentors@googlegroups.com/ To unsubscribe from this group, send email to jsmentors+unsubscr...@googlegroups.com