File tree Expand file tree Collapse file tree 2 files changed +54
-0
lines changed
3.1.2-undersocre 整体结构 & 面向对象风格支持 Expand file tree Collapse file tree 2 files changed +54
-0
lines changed Original file line number Diff line number Diff line change 1+ ( function ( root ) {
2+ var _ = function ( ) {
3+
4+ }
5+
6+ var _ = function ( obj ) {
7+ if ( obj instanceof _ ) {
8+ return obj ;
9+ }
10+
11+ if ( ! ( this instanceof _ ) ) {
12+ return new _ ( obj )
13+ }
14+
15+ this . _wrapped = obj ;
16+ }
17+
18+ _ . unique = function ( arr , callback ) {
19+ var ret = [ ] ;
20+ var target , i = 0 ;
21+ for ( ; i < arr . length ; i ++ ) {
22+ target = callbacks ? callbacks ( arr [ i ] ) : arr [ i ] ;
23+ if ( ret . indexOf ( target ) === - 1 ) {
24+ ret . push ( target )
25+ }
26+ }
27+ }
28+
29+ _ . map = function ( ) {
30+
31+ }
32+
33+ _ . each = function ( target , callback ) {
34+ var key , i = 0 ;
35+ if ( _ . isArray ( target ) ) {
36+ var length = target . length
37+ for ( ; i < length ; i ++ ) {
38+ callback . call ( target , target [ i ] )
39+ }
40+ } else {
41+ for ( key in target ) {
42+ callback . call ( target , key , target [ key ] )
43+ }
44+ }
45+ }
46+
47+ //给underscore原型上面扩展方法
48+
49+ _ . mixin = function ( obj ) {
50+ _ . each ( _ . function )
51+ }
52+
53+ root . _ = _
54+ } ) ( this )
You can’t perform that action at this time.
0 commit comments