전체 글

· Javascript
Class는 뭐다? constructor 메소드를 사용해 보다 쉽게 객체를 만드는 공장! prototype 기반의 객체를 만드는 공장이 있고, (보기쉬움) class 기반의 객체를 만드는 공장이 있다. // 생성된 객체를 어떻게 초기화? // 먼저 실행되도록 만들어진 constructor 함수를 class 내에서 구현 class Person { constructor(name, first, second){ this.name =name; this.first=first; this.second=second; } sum=()=>{ return 'class : '+(this.first+this.second); } } let kim = new Person('kim',10,20); kim.sum = function()..
· Javascript
prototype(유전자) -객체들이 공통적으로 사용하는 속성값 프로토타입을 사용하지 않고, 생성자 함수 안에서 메소드를 직접 정의한다면 어떤 비효율? - 객체를 생성할때마다 중복적인 메소드로 인해, 메모리 낭비가 생김 그 비효율을 프로토 타입을 통해 어떻게 극복했는지? -객체들이 공통으로 사용하는 속성값(프로토타입)을 정의해서, 객체 안에 일일이 메소드를 쓰는 과정을 생략해, 효율적인 메모리 사용가능 function Person(name,first,second){ this.name =name; this.first=first; this.second=second; } //형태 Person.prototype.sum=function(){ return 'prototype : '+(this.first+this.s..
· Javascript
Constructor function(생성자 함수) 객체 양산 함수, 즉 객체를 찍어내는 함수이다. 이전에는 하나의 객체마다 키와 값을 부여해줬다면, 컨스트럭터와 new 라는 객체생성 키워드를 사용하여 컨스트럭터에 정의되어 있는 속성과 메소드를 한번에 받아올 수 있고, 각각의 값은 매개변수로 받아 각 상황마다 변경하여 사용할 수 있다. // 함수에 매개변수를 만들어준다 function Person(name,first,second,third){ this.name =name; this.first=first; this.second=second; this.third=third; this.sum=function(){ return this.first+this.second+this.third; } } // 생성자함수..
· Javascript
this = '나'! this는 this가 속해있는 메소드가 속해있는 객체를 가리킴! 객체의 이름이 바뀌어도 원래의 로직을 유지할 수 있어서 재사용에 도움이 됨. let kim = { name:'kim', first:10, second:20, sum:function(){ return this.first+this.second; } } console.log("kim.sum()",kim.sum()); //kim.sum() 30
· Javascript
//내장객체 Math console.log("Math.PI", Math.PI); console.log("Math.random()",Math.random());//객체에 소속되어 있을때는 메소드, 메소드는 본질적으로 함수 console.log("Math.floor(2.6)",Math.floor(2.6)); //나만의 객체 만들어보기 //객체는 그룹핑해서 이름을 붙인것이다 let MyMath = { PI:Math.PI, random:function(){ return Math.random(); }, floor:function(val){ return Math.floor(val); } } console.log("MyMath.PI",MyMath.PI); console.log("MyMath.random",MyMath..
· Javascript
let memberArray = ['지은','연미','뽀미']; console.group('array loop'); let i =0; while(i
· Javascript
객체란? 서로 연관된 변수와 함수를 그룹핑하고 이름을 붙인것! let memberArray = ['지은','연미','뽀미']; console.log('memberArray[0]',memberArray[0]);// '지은' let memberObject = { mom:'연미', daughter:'지은', dog:'뽀미' } memberObject.daughter = '귀여운 지으니' //재할당을 해줌 delete memberObject.mom; //mom 이라는 속성을 삭제 console.log('after delete memberObject.mom', memberObject.mom); //undefined console.log("memberObject.daughter",memberObject.daught..
becky(지은)
Know yourself, follow your passion