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

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

    }

});


慕姐8265434
浏览 556回答 1
1回答

江户川乱折腾

(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;});
打开App,查看更多内容
随时随地看视频慕课网APP

相关分类

JavaScript