본문 바로가기
jQuery

jQuery.fn.extend()

by Jundol 2015. 5. 14.

jQuery.fn & jQuery.fn.extend()



가끔 라이브러리 혹은 타 개발자가 작성한 소스코드를 보다보면 jQuery.fn 이 간혹 보이는데

기초가 부족한 필자는 jQuery.fn 이 뭔지 몰랐다.

찾아보니...


In jQuery, the fn property is just an alias to the prototype property.

그냥 가명이란다... 프로토타입의 가명으로 fn 을 사용한다고 한다.


jQuery.fn = jQuery.prototype = {

       //...

}

그렇다하면~ jQuery.fn.extend() 는 jQuery 를 확장 즉 커스터마이징 한다는 뜻이다.

jQuery 의 기본 함수에 추가하는 내가 쓰고자 하는 함수를 넣어서 확장시킬 수 있다.


<script>
jQuery.fn.extend({
check: function() {
return this.each(function() {
this.checked = true;
});
},
uncheck: function() {
return this.each(function() {
this.checked = false;
});
}
});
// Use the newly created .check() method
$( "input[type='checkbox']" ).check();
</script>


요로케~ 확장이 가능하다.


출처

1. stackoverflow
http://stackoverflow.com/questions/4083351/what-does-jquery-fn-mean

2. jQuery
http://api.jquery.com/jquery.fn.extend/

'jQuery' 카테고리의 다른 글

jquery.toggle()  (0) 2015.06.12

댓글