처음에 내 자신의 코드를 작성하기 시작한 후에 jQuery의 '향상된'init 생성자를 나중에 이해할 때까지는 다른 방법으로 객체를 구성해야했습니다. 내 옛날 방식을 유지해야하는지 아니면 내 자신의 '향상된'init 생성자를 사용해야하는지 궁금합니다.더 좋은 초기화 형태는 무엇입니까?
내 생성자 :
var $ = function(selector,context,createObj) {
if(createObj) {
// actually initiating object
} else {
return new $(selector,context,true);
}
};
jQuery를 :
jQuery = function(selector, context) {
// The jQuery object is actually just the init constructor 'enhanced'
return new jQuery.fn.init(selector, context, rootjQuery);
};
실제 초기화 :
init: function(selector, context, rootjQuery) {
// some code
}
변경 프로토 타입 (jQuery.prototype.init.prototype = jQuery.prototype) :
jQuery.fn.init.prototype = jQuery.fn;
대체 방법을 보여줄 수 있으면 멋지게 될 것입니다. – JJJ
jQuery의 생성자가 추가되었습니다. – FrameDev