0

我正在编写自己的 JavaScript 库。我该怎么做才能以这种方式扩展我的对象?

_.mymethod();

这是我的代码:

(function (window, undefined) {
    "use strict";

    var emptyArray = [];

    function _(id) {
        return new _.fd.init(id);
    }

    _.fd = _.prototype = {
        init: function (selector) {
            this.el = document.getElementById(sel);
            return this;
        },
        replaceText: function (text) {
            this.el.innerHTML = text;
            return this;
        },
        changeTextColor: function (color) {
            this.el.style.color = color;
            return this;
        }
    };

    _.fd.init.prototype = _.fd;
    _.extend = function (target) {};
    _.extend({});

    window._ = _;
}(window));

关键是,如何扩展使用方法,如

_.method();
4

0 回答 0