메서드가 객체를 반환하게 되면, 메서드의 반환 값인 객체를 통해 또 다른 함수를 호출
<script>
var MySquare = function(){
this._width = 0;
this._height = 0;
this._x = 0;
this._y = 0;
this._color = "";
}
MySquare.prototype.setWidth = function( _w ){
this._width = _w;
};
MySquare.prototype.setHeight = function( _h ){
this._height = _h;
};
MySquare.prototype.setX = function( _x ){
this._x = _x;
}
MySquare.prototype.setY = function( _y ){
this._y = _y;
}
MySquare.prototype.setColor = function( _c ){
this._color = _c;
}
MySquare.prototype.getInfo = function(){
console.log( this._width );
console.log( this._height );
console.log( this._x );
console.log( this._y );
console.log( this._color );
}
//객체 값 지정 및 호출
var _square = new MySquare();
_square.setWidth( 100 );
_square.setHeight( 100 );
_square.setX( 100 );
_square.setY( 100 );
_square.setColor( "red" );
_square.getInfo();
</script>
'javascript' 카테고리의 다른 글
콜백함수 (0) | 2020.03.13 |
---|---|
VIDEO TAGE 관련된 내용 정리 (0) | 2018.11.15 |
for문 object (0) | 2018.03.21 |
for문 (0) | 2018.03.21 |
[jQuery] jquery hide() show() animate() (0) | 2016.12.20 |