为了账号安全,请及时绑定邮箱和手机立即绑定

如何改写成兼容amd和普通方式调用?

如何改写成兼容amd和普通方式调用?

慕姐8265434 2018-11-29 11:14:02
define("utils.ClassUtil", function () {    /**     * @summary 寄生组合式继承     * @param subType 子类     * @param superType 超类     * @memberof ClassUtil     */    function inheritPrototype(subType, superType) {        var prototype = object(superType.prototype);        prototype.constructor = subType;        subType.prototype = prototype;    }    /**     * @summary 返回构造函数     * @memberof ClassUtil     */    function object(o) {        function F () {}        F.prototype = o;        return new F();    }    return {        inheritPrototype:inheritPrototype    }});
查看完整描述

1 回答

?
江户川乱折腾

TA贡献1851条经验 获得超5个赞

(function (factory) {

    'use strict';

    if (typeof define === "function" && define.amd) {

        // AMD. Register as an anonymous module.

        define("utils.ClassUtil",[], factory);

    } else {

        // Browser globals

        factory(this.jQuery);

    }

}).call(this, function ($) {

    /**

     * @summary 寄生组合式继承

     * @param subType 子类

     * @param superType 超类

     * @memberof ClassUtil

     */

    function inheritPrototype(subType, superType) {

        var prototype = object(superType.prototype);

        prototype.constructor = subType;

        subType.prototype = prototype;

    }

    /**

     * @summary 返回构造函数

     * @memberof ClassUtil

     */

    function object(o) {

        function F() { }

        F.prototype = o;

        return new F();

    }

    var exports = {

        inheritPrototype: inheritPrototype

    }

    this.utils = this.utils || {};

    this.utils.ClassUtil = exports;

    return exports;

});


查看完整回答
反对 回复 2018-12-30
  • 1 回答
  • 0 关注
  • 555 浏览
慕课专栏
更多

添加回答

举报

0/150
提交
取消
微信客服

购课补贴
联系客服咨询优惠详情

帮助反馈 APP下载

慕课网APP
您的移动学习伙伴

公众号

扫描二维码
关注慕课网微信公众号