码迷,mamicode.com
首页 > Web开发 > 详细

JS学习笔记03-初识继承

时间:2014-06-02 09:35:04      阅读:171      评论:0      收藏:0      [点我收藏+]

标签:c   style   class   blog   code   java   

bubuko.com,布布扣
<!DOCTYPE HTML>
<html lang="en">
<head>
 <meta charset="UTF-8"> 
    <title>test</title>
    <style type="text/css">    
    </style>
    </head>
    
<body>
     <script type="text/javascript">
     // ◆prototype方式
     var Widget = function(){
        title = ‘‘;     
        this.getTitle=function(){
                return this.title;
        }
         this.setTitle=function(){
                this.title = arguments[0];
        } 
    }

    
    var Button = function(){}
    Button.prototype = new Widget();

    
    var Edit = function(){}
    Edit.prototype = new Widget(); 

    
    var btn = new Button();
    btn.setTitle(button title name);

    
    var edt = new Edit();
    edt.setTitle(edit title name);

    
    //当前对象中找不到时,查找prototype属性
    console.log(edt.getTitle()); 
    console.log(btn.getTitle()); 
    console.log(btn.title+ +edt.title); 
    
    

// ◆call+prototype方式 var Toolbar = function(){ Widget.call(this); Toolbar.prototype = new Widget(); this.setTitle(arguments[0]); } var toolbar = new Toolbar(toolbar title name); console.log(toolbar.getTitle() + + toolbar.title); </script> </body>
bubuko.com,布布扣

 

 

JS学习笔记03-初识继承,布布扣,bubuko.com

JS学习笔记03-初识继承

标签:c   style   class   blog   code   java   

原文地址:http://www.cnblogs.com/fuyunlong/p/3763485.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!