<h3>일급객체 만족 조건</h3>
<p>1. 무명의 <strong>리터럴</strong>로 생성할 수 있다. 즉, 런타임에 생성이 가능하다.</p>
<p>2. 변수나 자료구조(객체, 배열, 데이터)에 함수를 <strong>할당</strong> 할 수 있다.</p>
<button onClick="add(1,2)">1+2</button>
<button onClick="newAdd()">2+3 할당</button>
<p>3. 함수를 인자로 <strong>전달</strong> 할 수 있다.</p>
<button id="send1">전달 1</button>
<button id="send2">전달 2</button>
<p>4. 함수를 <strong>반환</strong> 할수 있다.</p>
<button onClick="add5(5)">반환</button>
var add = function(a,b) {
  var sum = a+b;
  console.log(sum);
  return sum;
}
var newAdd = function(){
  var overrideAdd = add(2,3);
  overrideAdd;
}

function showText() {
    console.log(this.id);
}
$('#send1').on('click',showText);
$('#send2').on('click',showText);

function addReturn(a) {
    return function(b) {
      var sum = a+b;
      console.log(sum);
      return sum;
    }   
}
var add5 = function(e){
  var changedAddReturn = addReturn(e);
  changedAddReturn(5);
}

External CSS

This Pen doesn't use any external CSS resources.

External JavaScript

  1. https://cdnjs.cloudflare.com/ajax/libs/jquery/3.5.1/jquery.min.js