javascript - Trouble running an Observer Pattern example -
i trying reproduce observer pattern example given in book learning javascript design patterns error in extend
function:
i using code in book starting below line:
first, let's model list of dependent observers subject may have:
i have set code in fiddle , i'd understand why i'm getting error.
the issue in reported error in question first argument extend()
not valid object.
when run jsfiddle, reports observer not defined
.
if observer()
pattern should parallel subject()
pattern, missing piece of code:
function observer() { this.observers = new observerlist(); }
or, perhaps need change:
extend( new observer(), check );
to:
extend( new observerlist(), check );
so uses code show observerlist()
.
in fact, when press button in jsfiddle, error occurs uncaught referenceerror: observer not defined
further confirms above.
and, when apply change, code seems run here: http://jsfiddle.net/jfriend00/8xmu1mcg/, though don't know it's supposed do, adds checkbox , there no errors.
Comments
Post a Comment