// 명시적 함수
function fn(){
return this;
}
console.log(typeof fn);
// 익명 함수 or 함수 생성자(아래와 코드와 같이 함수 몸체를 "문자열"로 할당하는 표현식 때문에 코드 가독성이 떨어지는 단점이 존재한다. 하지만 필요한 경우 유용히 사용할 수 있다.)
var fn = (function(body){
return new Function('x', 'y', body);
})('return x + y;');
console.log(fn(1, 2));
// 익명함수
var fn = function(){
return this;
}
console.log(fn);
// 함수 리터럴도 명시적인 이름을 줄 수 있지만 이것은 함수 안에서만 접근 가능하다.
var fn = function _fn(){
// _fn 기명 함수는 리터럴 내부에서만 접근 가능하며, 외부에서 호출 시 선언되지 않았다는 오류를 발생한다.
return _fn;
}
console.log(fn);
try{
console.log(fn1);
}
catch(e){
console.log(e.message);
}
Please Whitelist JSFiddle in your content blocker.
Help keep JSFiddle free for always by one of two ways:
Whitelist JSFiddle in your content blocker (two clicks)
Go PRO and get access to additional PRO features →
Join the 4+ million users, and keep the JSFiddle dream alive.
Ad-free
All ads in the editor and listing pages are turned completely off.
Use pre-released features
You get to try and use features (like the Palette Color Generator) months before everyone else.
Fiddle collections
Sort and categorize your Fiddles into multiple collections.
Private collections and fiddles
You can make as many Private Fiddles, and Private Collections as you wish!
Console
Debug your Fiddle with a minimal built-in JavaScript console.