zoukankan      html  css  js  c++  java
  • JavaScript——面向对象以及基于类的继承

    View Code
     1 /*###########################################*
     2  * 1.通过prototype建立面向对象的JavaScript
     3  * 2.基于类的继承
     4  ###########################################*/
     5 
     6 /*##################1#################*/
     7 /*创建交通工具的构造方法*/
     8 function Vehicle() {
     9     /*交通工具属性*/
    10     var wheelCounts = 4;//车轮数
    11     var curbWeightInPounds = 3000;//车子重量
    12     
    13     this.getWheelCounts = function() {
    14         return wheelCounts;
    15     } ;
    16     this.getCurbWeightInPounds = function() {
    17         return curbWeightInPounds;
    18     } ;
    19     
    20     this.setWheelCounts = function(wc) {
    21         wheelCounts = wc;
    22     } ;
    23     this.setCurbWeightInPounds = function(cwp) {
    24         curbWeightInPounds = cwp;
    25     } ;
    26     //燃料
    27     this.refueling = function() {
    28         return "refueiing...";
    29     };
    30 
    31     //主要任务
    32     this.mainTasks = function() {
    33         return "Go to school, shop and so on.";
    34     };
    35     
    36 };
    37 
    38 
    39 
    40 /*赛车*/
    41 function SPortsCar() {
    42 
    43     //燃料
    44     SPortsCar.prototype.refueling = function() {
    45         return "SPortsCar refueiing 3000";
    46     };
    47 
    48     //主要任务
    49     SPortsCar.prototype.mainTasks = function() {
    50         return "SPortsCar driving, loking good, driving beach. ";
    51     };
    52     
    53 };
    54 
    55 /*对象之间的复制**/
    56 function copyObject() {
    57     
    58     this.createCopyObject = function (parent, child) {
    59         for(var prototype in parent)
    60         {
    61             if(!child[prototype]){
    62                 child[prototype] = parent[prototype];
    63             }
    64         };
    65     };
    66     
    67 }
  • 相关阅读:
    Vue中发送HTTP请求
    Vuex
    vue-cli
    Vue基础2
    Vue基础1
    webpack_vue
    前言:数据库典型架构实践
    MySQL数据库优化
    解析 PHP 中 session 的实现原理以及大网站应用应该注意的问题
    Yii2.0 下的 load() 方法的使用
  • 原文地址:https://www.cnblogs.com/FCWORLD/p/2877112.html
Copyright © 2011-2022 走看看