zoukankan      html  css  js  c++  java
  • JS实现extend函数

     

    //写一个函数,该函数的名称是extend,有两个参数:destination,source

    1、如果destination和source都是json对象,完成从source到destination的复制
    2、如果destination是一个函数,source是一个json对象,则把source中的每一个key,value对赋值给destination的prototype
    3、如果destination,source都是函数,则把source的prototype中的内容赋值给destination的prototype


    1
    var extend = function(destination,source){ 2 if(typeof destination == "object"){//destination是一个json对象 3 if(typeof source == "object"){//source是一个json对象 4 //把source中的每一个key,value值赋值给destination 5 for(var i in source){ 6 destination[i] = source[i]; 7 } 8 } 9 } 10 11 if(typeof destination == "function"){ 12 if(typeof source == "object"){ 13 for(var i in source){ 14 destination.prototype[i] = source[i]; 15 } 16 } 17 if(typeof source == "function"){ 18 destination.prototype = source.prototype; 19 } 20 } 21 return destination; 22 }
  • 相关阅读:
    QString 与 string转换
    Lua 判断表是否为空方法
    QT 继承QWidget && 继承QDialog
    QNetworkAccessManager
    Lua语言特色
    Lua逻辑操作符
    Lua语言总结
    Lua 函数
    Lua数据类型
    QT 通过QNetworkReply *获取对应请求的URL地址
  • 原文地址:https://www.cnblogs.com/Magiccwl/p/7295895.html
Copyright © 2011-2022 走看看