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 / Execution-ContextEx1.js
Created June 6, 2018 11:47
์‹คํ–‰ ์ปจํ…์ŠคํŠธ ์˜ˆ์‹œ
console.log("์ „์—ญ ์ฝ”๋“œ");
//์ „์—ญ ์ฝ”๋“œ ์ถœ๋ ฅ
function1() {
console.log("function1");
}
function2() {
function1();
console.log("function2");
}
@khg0712
khg0712 / prototype-chaining10.js
Last active May 30, 2018 11:08
๋ž˜ํผ ๊ฐ์ฒด4
1 .toString();//1๊ณผ .์„ ๋„์–ด์“ฐ๊ธฐํ•ด์„œ ์†Œ์ˆ˜๊ฐ€ ์•„๋‹˜์„ ์•Œ๋ฆฐ๋‹ค.
1..toString();//1.์—์„œ .์„ ๋ฏธ๋ฆฌ ์จ๋‘์–ด ๋’ค์— ์žˆ๋Š” .์ด ์†Œ์ˆ˜๋ฅผ ํ‘œํ˜„ํ•˜๋Š” ๊ฒƒ์ด ์•„๋‹ˆ๋ผ ์ฐธ์กฐ ์—ฐ์‚ฐ์ž์ž„์„ ์•Œ๋ฆฐ๋‹ค.
@khg0712
khg0712 / prototype-chaining9.js
Created May 30, 2018 11:01
๋””ํดํŠธ ํ”„๋กœํ† ํƒ€์ž… ๊ฐ์ฒด์˜ ๋ณ€๊ฒฝ
function Animal(name) {
this.name = name;
this.species = "frog"
}
var frog = new Animal("James");
Animal.prototype = {
country: "Korea"
};//Animal ์ƒ์„ฑ์ž์˜ ํ”„๋กœํ† ํƒ€์ž… ๊ฐ์ฒด ๋ณ€๊ฒฝ
@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);
};
@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-chaining6.js
Created May 30, 2018 10:59
ํ‘œ์ค€ ๋‚ด์žฅ ๊ฐ์ฒด์˜ ํ”„๋กœํ† ํƒ€์ž… ๊ฐ์ฒด
Number.prototype.prop = 1;
var a = 1;
console.log(a.prop);//1 ์ถœ๋ ฅ
@khg0712
khg0712 / prototype-chaining5.js
Created May 30, 2018 10:58
๋ž˜ํผ ๊ฐ์ฒด3
1.toString();//error
@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-chaining3.js
Created May 30, 2018 10:57
๋ž˜ํผ ๊ฐ์ฒด1
"hello".toUpperCase();//new String(myWord).toUpperCase();
@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 ๊ฐ์ฒด