本来笔记已经渐入佳境,但是今天状态竟然不太对,回头想想题目都不难,可是我竟然写的都不好。
1.实现jquery,关键在于init的原型,这里我太执着于用this了,其实用外界的引用就好了。
$(".this").attr("name","value").html();
var $ = function (selector) {
return new $.fn.init(selector);
};
$.fn = $.prototype;
$.prototype.init = function (selector) {
this.element = document.querySelector(selector);
};
$.prototype.attr=function (name,value) {
this.element.setAttribute(name,value);
return this;
};
$.prototype.html = function () {
return this.element.innerHTML;
}
$.fn.init.prototype = $.fn;
var cc = $(".this").attr("name","value").html();