• 博客园logo
  • 会员
  • 众包
  • 新闻
  • 博问
  • 闪存
  • 赞助商
  • HarmonyOS
  • Chat2DB
    • 搜索
      所有博客
    • 搜索
      当前博客
  • 写随笔 我的博客 短消息 简洁模式
    用户头像
    我的博客 我的园子 账号设置 会员中心 简洁模式 ... 退出登录
    注册 登录
return false
不曾后悔的选择……
博客园    首页    新随笔    联系   管理     
javascript call()函数

js中的call()函数,简单的说就是用来纠正指正的吧!

调用一个对象的方法,用另一个对象替换当前对象,这样说显得相当的空洞与抽象,实例说明一切!

 1 <script type="text/javascript">
 2 function person(name){//带参数的构造函数
 3     this.name=name; //定义并初始化属性
 4     this.SayHello=function(){//定义对象方法
 5         alert("hello I`m " + this.name);
 6     }
 7 }
 8 
 9 function Employee(name,salary){
10 
11     person.call(this,name);//用call调用父构造函数,this指当前的构造函数Employee,所以就是用person替换Employee
12     this.salary=salary;
13 this.showMe=function(){ 14 alert(this.name + "$" + this.salary); 15  } 16 } 17 18 var BillGates=new person("Bill Gates");//创建person类的Billgates对象 19 var SteveJobs=new Employee("Steve Jobs",1234);//创建Employee类的stevejobs对象 20 21 BillGates.SayHello();//输出hello I`m Bill Gates 22 SteveJobs.SayHello();//输出hello I`m Steve Jobs 23 SteveJobs.showMe();//输出Steve Jobs $ 1234 24 </script>

本人菜鸟一只!解释不清楚,请见谅!

posted on 2013-08-21 11:01  return false  阅读(291)  评论(0)    收藏  举报
刷新页面返回顶部
博客园  ©  2004-2025
浙公网安备 33010602011771号 浙ICP备2021040463号-3