Skip to content

Instantly share code, notes, and snippets.

View khg0712's full-sized avatar
🎯
Focusing

Hugo Kim khg0712

🎯
Focusing
View GitHub Profile
@khg0712
khg0712 / JS-function-type-Example5.js
Created May 19, 2018 16:30
κΈ°λͺ… ν•¨μˆ˜ ν‘œν˜„μ‹ μž¬κ·€ν•¨μˆ˜ μ˜ˆμ‹œ
var factorial = function factorialFunc(num) {
if(num <= 1) {
return num;
}
return (num * factorialFunc(num-1));
};
console.log(factorial(3));//6 λ°˜ν™˜
@khg0712
khg0712 / JS-function-type-Example6.js
Created May 19, 2018 16:32
Function μƒμ„±μžλ₯Ό ν†΅ν•œ ν•¨μˆ˜ 생성 μ˜ˆμ‹œ
var add = new Function('a','b','return a + b');
add(1,2);//3 λ°˜ν™˜
@khg0712
khg0712 / JS-function-type-Example7.js
Created May 19, 2018 16:35
ν•¨μˆ˜ ν‘œν˜„μ‹ ν•¨μˆ˜ ν˜Έμ΄μŠ€νŒ… 비ꡐ μ˜ˆμ‹œ
add(1,2);//μ—λŸ¬ λ°œμƒ
var add = function(a,b) {
return a + b;
};
add(1,2);//3 λ°˜ν™˜
@khg0712
khg0712 / JS-function-type-Example8.js
Created May 19, 2018 16:37
ν•¨μˆ˜ ν”„λ‘œνΌν‹° μ˜ˆμ‹œ
var add = function(a,b) {
return a + b;
};
add.k = 0;
console.log(add.k);//0 좜λ ₯
@khg0712
khg0712 / JS-function-type-Example9.js
Created May 19, 2018 17:06
ν•¨μˆ˜μ˜ ν”„λ‘œν† νƒ€μž… μ˜ˆμ‹œ
function person (name){
this.name = name;
}
console.dir(person.prototype);
console.dir(person.prototype.constructor);
@khg0712
khg0712 / JS-function-type-Example10.js
Created May 19, 2018 17:18
μžλ°”μŠ€ν¬λ¦½νŠΈ ν•¨μˆ˜μ˜ νŠΉμ„± μ˜ˆμ‹œ
function average(arg1, arg2, arg3) {
return (arg1 + arg2 + arg3)/3;
}
average(1);//NaN
average(1,2);//NaN
average(1,2,3);//2
@khg0712
khg0712 / JS-function-type-Example11.js
Created May 19, 2018 17:19
arguments 객체 μ‚¬μš© μ˜ˆμ‹œ
function average() {
var sum = 0;
for(var i = 0; i<arguments.length; i++) {
sum += arguments[i];
}
return sum/arguments.length;
}
average(1,2,3,4,5);//3 λ°˜ν™˜
@khg0712
khg0712 / JS-function-type-Example12.js
Created May 19, 2018 17:21
this의 μ—­ν•  μ˜ˆμ‹œ
var my = {
name: 'my',
sayName() {
console.log(this.name);
}
};
var other = {
name: 'other'
};
@khg0712
khg0712 / JS-function-type-Example13.js
Created May 19, 2018 17:24
λ‚΄λΆ€ ν•¨μˆ˜μ˜ this 바인딩 μ˜ˆμ‹œ
var a = 10;//μ „μ—­ λ³€μˆ˜ a 생성
var object = {
a: 1,
func1: function() {
this.a += 1;
console.log('func1: ' + this.a);
var func2 = function () {
this.a += 1;
console.log('func2: ' + this.a);
var func3 = function () {
@khg0712
khg0712 / JS-function-type-Example13.js
Created May 19, 2018 17:27
λ‚΄λΆ€ ν•¨μˆ˜μ—μ„œ thisλ₯Ό λ³€μˆ˜μ— μ €μž₯ν•˜λŠ” μ˜ˆμ‹œ
var a = 10;//μ „μ—­ λ³€μˆ˜ a 생성
var object = {
a: 1,
func1: function() {
var that = this;//that λ³€μˆ˜μ— this μ €μž₯
this.a += 1;
console.log('func1: ' + this.a);
var func2 = function () {
that.a += 1;
console.log('func2: ' + that.a);