JS 继承的方式
1.使用call的方式
2. code如下
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
|
<!DOCTYPE html> <html lang= "en" >
<head> <meta charset= "UTF-8" >
<title>Title</title>
</head> <body> <script type= "text/javascript" >
//继承的第二种实现方式,call方法方式, Function对象中的方法
function test(str, str2) {
alert( this .name + ", " + str + ", " + str2)
}
var object = new Object();
object.name = "zhangsanfeng" ;
//test.call相当于调用了test函数
test.call(object, "ssy" , "hello" ); //将object赋值给this
</script> </body> </html> |
本文转自Work Hard Work Smart博客园博客,原文链接:http://www.cnblogs.com/linlf03/p/7295192.html,如需转载请自行联系原作者