데이터 타입 : 데이터의 형태를 의미하며, 객체와 객체가 아닌것으로 구분한다.

 

원시/기본 데이터 타입 : 객체가 아닌 데이터 타입이다.
  - 숫자
  - 문자열
  - boolean(true/false)
  - null
  - undefined

 

래퍼객체 : 원시 데이터형을 객체처럼 다룰수 있도록 하기 위한 객체다.
  - Number
  - String
  - Boolean

'Programming > Javascript' 카테고리의 다른 글

복제, 참조, 함수  (0) 2018.01.03
표준내장객체, Object 객체  (0) 2018.01.03
상속, prototype  (0) 2018.01.03
전역객체와 this  (0) 2018.01.03
생성자와 new  (0) 2018.01.03
블로그 이미지

꼴통보안인

,

표준 내장객체(Standard Built-in Object) : 자바스크립트가 기본적으로 가지고 있는 객체들이다. 프로그래밍을 하는데 기본적으로 필요한 도구들이기 때문에 중요하다.
  - Object
  - Function
  - Array
  - String
  - Boolean
  - Number
  - Math
  - Date
  - RegExp

예제
//
var arr = new Array('seoul','daejeon','daegu','pusan', 'gwangju');
function getRandomValueFromArray(arr){
    var index = Math.floor(arr.length*Math.random());
    return arr[index];
}
console.log(getRandomValueFromArray(arr));

 

//
Array.prototype.random = function(){
    var index = Math.floor(this.length*Math.random());
    return this[index];
}
var arr = new Array('seoul','daejeon','daegu','pusan', 'gwangju');
console.log(arr.random());

 

Object 객체 : 객체의 가장 기본적인 형태를 가지고 있는 객체다. 아무것도 상속받지 않는 순수한 객체이며. 값을 저장하는 기본적인 단위로 사용한다.
예시
<!DOCTYPE html>
<html>
<head>
 <title></title>
</head>
<body>
<script type="text/javascript">

//Object.keys()
var arr=["a","b","c"];
console.log('Object.keys(arr)',Object.keys(arr));

//Object.prototype.toString()
var o = new Object();
console.log('o.toString()', o.toString());

var a = new Array(1,2,3);
console.log(a.toString()', a.toString());
</script>
</body>
</html>

 

//
Object.prototype.contain = function(neddle) {
    for(var name in this){
        if(this[name] === neddle){
            return true;
        }
    }
    return false;
}
var o = {'name':'egoing', 'city':'seoul'}
console.log(o.contain('egoing'));
var a = ['egoing','leezche','grapittie'];
console.log(a.contain('leezche'));

 

'Programming > Javascript' 카테고리의 다른 글

복제, 참조, 함수  (0) 2018.01.03
데이터 타입, 래퍼객체  (0) 2018.01.03
상속, prototype  (0) 2018.01.03
전역객체와 this  (0) 2018.01.03
생성자와 new  (0) 2018.01.03
블로그 이미지

꼴통보안인

,

상속 : 객체의 로직을 그대로 물려받는 또 다른 객체를 만들 수 있는 기능을 의미한다. 기존의 로직을 수정하고 변경해서 파생된 새로운 객체를 만들 수 있게 해준다.
예시
//
function Person(name) {
 this.name=name;
 this.introduce=function (){
  return 'My name is '+this.name;
 }
}
var p1 = new Person('gildong');
document.write(p1.indroduce()+"<br />");

 

//
function Person(name) {
 this.name=name;
}
Person.prototype.name=null;
Person.prototype.introduce=function (){
 return 'My name is '+this.name;
}
var p1 = new Person('gildong');
document.write(p1.introduce()+"<br />");

 

//
function Person(name) {
 this.name=name;
}
Person.prototype.name=null;
Person.prototype.introduce=function (){
 return 'My name is '+this.name;
}

function Programmer(name){
 this.name=name;
}
Programmer.prototype = new Person();
var p1=new Programmer('gildong');
document.write(p1.introduce()+"<br />");

 

//
function Person(name){
    this.name = name;
}
Person.prototype.name=null;
Person.prototype.introduce = function(){
    return 'My name is '+this.name;
}
 
function Programmer(name){
    this.name = name;
}
Programmer.prototype = new Person();
Programmer.prototype.coding = function(){
    return "hello world";
}
 
var p1 = new Programmer('egoing');

document.write(p1.introduce()+"<br />");
document.write(p1.coding()+"<br />");

 

prototype : 객체의 원형이다. prototype에 저장된 속성들은 생성자를 통해서 객체가 만들어질 때 그 객체에 연결된다. 객체와 객체를 연결하는 체인의 역할을 한다. 이러한 관계를 prototype chain이라 한다.
예제
//
function Ultra(){}
Ultra.prototype.ultraProp = true;
 
function Super(){}
Super.prototype = new Ultra();
 
function Sub(){}
Sub.prototype = new Super();
 
var o = new Sub();
console.log(o.ultraProp);

 

'Programming > Javascript' 카테고리의 다른 글

데이터 타입, 래퍼객체  (0) 2018.01.03
표준내장객체, Object 객체  (0) 2018.01.03
전역객체와 this  (0) 2018.01.03
생성자와 new  (0) 2018.01.03
함수의 호출  (0) 2018.01.03
블로그 이미지

꼴통보안인

,