我正在编写自己的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();