File tree Expand file tree Collapse file tree 1 file changed +61
-0
lines changed
Expand file tree Collapse file tree 1 file changed +61
-0
lines changed Original file line number Diff line number Diff line change 1+ <!doctype html>
2+ < html lang ="en ">
3+ < head >
4+ < title > JavaScript Patterns</ title >
5+ < meta charset ="utf-8 ">
6+ </ head >
7+ < body >
8+ < script >
9+ // from https://gist.github.com/1174982
10+
11+ var NO_TOPIC = - 1 ;
12+ var Topic ;
13+
14+ function Handler ( s , t ) {
15+ this . successor = s || null ;
16+ this . topic = t || 0 ;
17+ }
18+
19+ Handler . prototype = {
20+ handle : function ( ) {
21+ console . log ( this . has ( ) )
22+ if ( this . successor ) {
23+ this . successor . handle ( )
24+ }
25+ console . log ( this . topic ) ;
26+ } ,
27+ has : function ( ) {
28+ return this . topic != NO_TOPIC ;
29+ }
30+ } ;
31+
32+ var _handle = Handler . prototype . handle ;
33+
34+ var app = new Handler ( {
35+ handle : function ( ) {
36+ console . log ( 'app handle' ) ;
37+ }
38+ } , 3 ) ;
39+
40+ var dialog = new Handler ( app , 1 ) ;
41+ //dialog.handle = function () {
42+ //if (this.has()) {
43+ //} else {
44+ //console.log('dialog handle');
45+ //_handle.call(this);
46+ //}
47+ //}
48+
49+ var button = new Handler ( dialog , 2 ) ;
50+ //button.handle = function () {
51+ //if (this.has()) {
52+ //} else {
53+ //console.log('dialog handle');
54+ //_handle.call(this);
55+ //}
56+ //}
57+
58+ button . handle ( ) ;
59+ </ script >
60+ </ body >
61+ </ html >
You can’t perform that action at this time.
0 commit comments