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-Example14.js
Created May 19, 2018 17:29
apply ๋ฉ”์„œ๋“œ ์˜ˆ์‹œ
function animal(name){
this.name = name;
}
var dog = {};
animal.apply(dog,['James']);//animal.call(dog,'James'); ์™€ ๊ฐ™๋‹ค.
console.dir(dog);
@khg0712
khg0712 / JS-function-type-Example15.js
Created May 19, 2018 17:30
arguments ๊ฐ์ฒด์— apply ๋ฉ”์„œ๋“œ๋ฅผ ํ†ตํ•œ ํ‘œ์ค€ ๋ฐฐ์—ด ๋ฉ”์„œ๋“œ ์‚ฌ์šฉ ์˜ˆ์‹œ
function myAdd(){
console.dir(arguments);
Array.prototype.shift.apply(arguments);
console.dir(arguments);
}
myAdd(1,2,3,4);
@khg0712
khg0712 / prototype-chaining1.js
Created May 30, 2018 10:48
๊ฐ์ฒด ๋ฆฌํ„ฐ๋Ÿด๋กœ ์ƒ์„ฑ๋œ ๊ฐ์ฒด์˜ ํ”„๋กœํ† ํƒ€์ž… ์ฒด์ด๋‹
var objectEx = {
prop1: 'k',
prop2: 1,
prop3: 'Hello'
};
console.log(objectEx.hasOwnProperty('prop1'));//true ์ถœ๋ ฅ
console.log(objectEx.hasOwnProperty('prop4'));//false ์ถœ๋ ฅ
console.dir(objectEx);
@khg0712
khg0712 / prototype-chaining2.js
Created May 30, 2018 10:49
์ƒ์„ฑ์ž ํ•จ์ˆ˜๋กœ ์ƒ์„ฑ๋œ ๊ฐ์ฒด์˜ ํ”„๋กœํ† ํƒ€์ž… ์ฒด์ด๋‹
function Animal(name, age, species) {
this.name = name;
this.age = age;
this.species = species;
}
var frog = new Animal('froll', 2, 'frog');
console.log(frog.hasOwnProperty('name'));//true ์ถœ๋ ฅ
console.log(frog.hasOwnProperty('fatherName'));//false ์ถœ๋ ฅ
console.dir(Animal.prototype);//Animal.prototype ๊ฐ์ฒด
@khg0712
khg0712 / prototype-chaining3.js
Created May 30, 2018 10:57
๋ž˜ํผ ๊ฐ์ฒด1
"hello".toUpperCase();//new String(myWord).toUpperCase();
@khg0712
khg0712 / prototype-chaining4.js
Created May 30, 2018 10:57
๋ž˜ํผ ๊ฐ์ฒด2
var myWord = "hello";
myWord.someProperty = 111; // new String(myWord).someProperty = 111;
@khg0712
khg0712 / prototype-chaining5.js
Created May 30, 2018 10:58
๋ž˜ํผ ๊ฐ์ฒด3
1.toString();//error
@khg0712
khg0712 / prototype-chaining6.js
Created May 30, 2018 10:59
ํ‘œ์ค€ ๋‚ด์žฅ ๊ฐ์ฒด์˜ ํ”„๋กœํ† ํƒ€์ž… ๊ฐ์ฒด
Number.prototype.prop = 1;
var a = 1;
console.log(a.prop);//1 ์ถœ๋ ฅ
@khg0712
khg0712 / prototype-chaining7.js
Created May 30, 2018 11:00
ํ”„๋กœํ† ํƒ€์ž… ๊ฐ์ฒด์˜ ํ”„๋กœํผํ‹ฐ ๋ณ€๊ฒฝ
function Animal (name) {
this.word = function() {
console.log("abcd");
};
this.name = name;
}
var dog = new Animal("James");
dog.word();//abcd ์ถœ๋ ฅ
@khg0712
khg0712 / prototype-chaining8.js
Created May 30, 2018 11:00
ํ”„๋กœํ† ํƒ€์ž… ๊ฐ์ฒด ๋ฉ”์„œ๋“œ์™€ this ๋ฐ”์ธ๋”ฉ
function Animal(species) {
this.species = species;
}
var frog = new Animal('frog');
frog.getSpecies();//Error
Animal.prototype.getSpecies = function() {
console.log(this.species);
};