File tree Expand file tree Collapse file tree 2 files changed +19
-1
lines changed Expand file tree Collapse file tree 2 files changed +19
-1
lines changed Original file line number Diff line number Diff line change 1- // 迭代器模式(Iterator Pattern)
1+ // 迭代器模式(Iterator Pattern)
2+
3+ let each = ( arr , callBack ) => {
4+ for ( let i = 0 ; i < arr . length ; i ++ ) {
5+ if ( callBack && callBack ( i , arr [ i ] ) === false ) {
6+ break ;
7+ }
8+ }
9+ }
10+
11+ let arr = [ 1 , 2 , 3 , 4 ]
12+ each ( arr , ( index , value ) => {
13+ if ( value > 2 ) return false
14+ console . log ( index , value )
15+ } )
Original file line number Diff line number Diff line change 113113
114114> [ 迭代器模式(Iterator Pattern)] ( /Example/Iterator-Pattern.js )
115115
116+ 定义:用于顺序访问集合对象的元素,不需要知道集合对象的底层表示。
117+ 目的:提供一种方法顺序访问一个聚合对象中各个元素, 而又无须暴露该对象的内部表示。
118+ 场景:$.each() for..of。
119+
116120> [ 命令模式(Command Pattern)] ( /Example/Command-Pattern.js )
117121
118122> [ 职责链模式(Chain of Responsibility Pattern)] ( /Example/Chain-Of-Responsibility-Pattern.js )
You can’t perform that action at this time.
0 commit comments