Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
xjbieke
axios
提交
ed4a39a5
A
axios
项目概览
xjbieke
/
axios
与 Fork 源项目一致
从无法访问的项目Fork
通知
2
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
A
axios
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
ed4a39a5
编写于
10月 28, 2015
作者:
M
Matt Zabriskie
浏览文件
操作
浏览文件
下载
差异文件
Merge pull request #127 from ctimmerm/ie8-arguments-foreach
Don't use utils.forEach to loop over arguments
上级
a090b052
1e2cb9bd
变更
3
隐藏空白更改
内联
并排
Showing
3 changed file
with
31 addition
and
66 deletion
+31
-66
lib/axios.js
lib/axios.js
+22
-31
lib/utils.js
lib/utils.js
+9
-22
test/specs/utils/forEach.spec.js
test/specs/utils/forEach.spec.js
+0
-13
未找到文件。
lib/axios.js
浏览文件 @
ed4a39a5
...
...
@@ -71,40 +71,31 @@ axios.spread = require('./helpers/spread');
// Expose interceptors
axios
.
interceptors
=
defaultInstance
.
interceptors
;
// Provide aliases for supported request methods
(
function
()
{
function
createShortMethods
()
{
utils
.
forEach
(
arguments
,
function
(
method
)
{
Axios
.
prototype
[
method
]
=
function
(
url
,
config
)
{
return
this
.
request
(
utils
.
merge
(
config
||
{},
{
method
:
method
,
url
:
url
}));
};
axios
[
method
]
=
bind
(
Axios
.
prototype
[
method
],
defaultInstance
);
});
}
function
createShortMethodsWithData
()
{
utils
.
forEach
(
arguments
,
function
(
method
)
{
Axios
.
prototype
[
method
]
=
function
(
url
,
data
,
config
)
{
return
this
.
request
(
utils
.
merge
(
config
||
{},
{
method
:
method
,
url
:
url
,
data
:
data
}));
};
axios
[
method
]
=
bind
(
Axios
.
prototype
[
method
],
defaultInstance
);
});
}
createShortMethods
(
'
delete
'
,
'
get
'
,
'
head
'
);
createShortMethodsWithData
(
'
post
'
,
'
put
'
,
'
patch
'
);
})();
// Helpers
function
bind
(
fn
,
thisArg
)
{
return
function
()
{
return
fn
.
apply
(
thisArg
,
Array
.
prototype
.
slice
.
call
(
arguments
));
};
}
// Provide aliases for supported request methods
utils
.
forEach
([
'
delete
'
,
'
get
'
,
'
head
'
],
function
(
method
)
{
Axios
.
prototype
[
method
]
=
function
(
url
,
config
)
{
return
this
.
request
(
utils
.
merge
(
config
||
{},
{
method
:
method
,
url
:
url
}));
};
axios
[
method
]
=
bind
(
Axios
.
prototype
[
method
],
defaultInstance
);
});
utils
.
forEach
([
'
post
'
,
'
put
'
,
'
patch
'
],
function
(
method
)
{
Axios
.
prototype
[
method
]
=
function
(
url
,
data
,
config
)
{
return
this
.
request
(
utils
.
merge
(
config
||
{},
{
method
:
method
,
url
:
url
,
data
:
data
}));
};
axios
[
method
]
=
bind
(
Axios
.
prototype
[
method
],
defaultInstance
);
});
lib/utils.js
浏览文件 @
ed4a39a5
...
...
@@ -130,16 +130,6 @@ function trim(str) {
return
str
.
replace
(
/^
\s
*/
,
''
).
replace
(
/
\s
*$/
,
''
);
}
/**
* Determine if a value is an Arguments object
*
* @param {Object} val The value to test
* @returns {boolean} True if value is an Arguments object, otherwise false
*/
function
isArguments
(
val
)
{
return
toString
.
call
(
val
)
===
'
[object Arguments]
'
;
}
/**
* Determine if we're running in a standard browser environment
*
...
...
@@ -151,7 +141,7 @@ function isArguments(val) {
* typeof document -> undefined
*
* react-native:
* typeof document.create
e
lement -> undefined
* typeof document.create
E
lement -> undefined
*/
function
isStandardBrowserEnv
()
{
return
(
...
...
@@ -164,7 +154,7 @@ function isStandardBrowserEnv() {
/**
* Iterate over an Array or an Object invoking a function for each item.
*
* If `obj` is an Array
or arguments
callback will be called passing
* If `obj` is an Array callback will be called passing
* the value, index, and complete array for each item.
*
* If 'obj' is an Object callback will be called passing
...
...
@@ -179,16 +169,13 @@ function forEach(obj, fn) {
return
;
}
// Check if obj is array-like
var
isArrayLike
=
isArray
(
obj
)
||
isArguments
(
obj
);
// Force an array if not already something iterable
if
(
typeof
obj
!==
'
object
'
&&
!
isArray
Like
)
{
if
(
typeof
obj
!==
'
object
'
&&
!
isArray
(
obj
)
)
{
obj
=
[
obj
];
}
// Iterate over array values
if
(
isArray
Like
)
{
if
(
isArray
(
obj
)
)
{
for
(
var
i
=
0
,
l
=
obj
.
length
;
i
<
l
;
i
++
)
{
fn
.
call
(
null
,
obj
[
i
],
i
,
obj
);
}
...
...
@@ -222,11 +209,11 @@ function forEach(obj, fn) {
*/
function
merge
(
/*obj1, obj2, obj3, ...*/
)
{
var
result
=
{};
forEach
(
arguments
,
function
(
obj
)
{
forEach
(
obj
,
function
(
val
,
key
)
{
result
[
key
]
=
val
;
}
);
}
);
var
assignValue
=
function
(
val
,
key
)
{
result
[
key
]
=
val
;
};
var
length
=
arguments
.
length
;
for
(
var
i
=
0
;
i
<
length
;
i
++
)
{
forEach
(
arguments
[
i
],
assignValue
);
}
return
result
;
}
...
...
test/specs/utils/forEach.spec.js
浏览文件 @
ed4a39a5
...
...
@@ -11,18 +11,6 @@ describe('utils::forEach', function () {
expect
(
sum
).
toEqual
(
15
);
});
it
(
'
should loop over arguments
'
,
function
()
{
var
sum
=
0
;
(
function
()
{
forEach
(
arguments
,
function
(
val
)
{
sum
+=
val
;
});
})(
1
,
2
,
3
,
4
,
5
);
expect
(
sum
).
toEqual
(
15
);
});
it
(
'
should loop over object keys
'
,
function
()
{
var
keys
=
''
;
var
vals
=
0
;
...
...
@@ -61,4 +49,3 @@ describe('utils::forEach', function () {
expect
(
count
).
toEqual
(
1
);
});
});
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录