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:

function draw(group){
    if(group instanceof Group){
        group.method1();
        group.method2();
        group.method3();
    } else {
        throw new Error("Shape Group Expected");
    }
}

vs

function draw2(group){
    if(typeof group == "object" && typeof group.method1 == "function"
       && typeof group.method2 == "function"
       && typeof group.method3 == "function"){
         //well, it looks like a group....
        group.method1();
        group.method2();
        group.method3(); //oops, its not the droid you're looking for
    } else {
        throw new Error("Shape Group Expected");
    }
}

-- 
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

Reply via email to