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 }
  • 相关阅读:
    Freemarker与Springmvc
    Freemarker与普通java
    Freemarker与Servlet
    跳舞的时间插件
    video标签播放视频
    字符串反转
    菲波拉契数列
    求所有子数组的和的最大值
    Spring AOP 5种通知与java动态代理
    线程维护日志队列
  • 原文地址:https://www.cnblogs.com/Magiccwl/p/7295895.html
Copyright © 2011-2022 走看看