본문 바로가기

Javascript

javascript class 만들어 쓰기

클래스 생성


//dataset object

function datasetObj(label, valueArr, color){

    this.label =  label;

    this.data =  valueArr;

    this.yaxis =  2;

    this.color =  color;

    this.points =  { symbol: "triangle", fillColor: color, show: true };

    this.lines = {show:true};

    this.points = {

radius:3,

fill:true,

show:true

    };

    this.splines = {

show: false,

tension: 0.6,

lineWidth: 1,

fill: 0.1

    };

    return this;

}



객체 생성


new datasetObj('유효전력량(kW)', activePowerArr, '#FF0000');


이런식으로 만들어서 사용했음!




추가.

이렇게 객체를 선언하는 함수의 경우 첫문자를 대문자로 써서 명시를 해주는 것이 좋다. 암묵적인 명명규칙이라는군.

function DatasetObj 이런 식으로.


추가..

여기서 공통으로 쓰고, 변하지 않는 항목은 프로토타입에 넣어놓는게 리소스상 좋다.


datasetObj.prototype.width = 150;
datasetObj.prototype.align = 'right';


'Javascript' 카테고리의 다른 글

동기화 처리  (0) 2017.01.06
Array.prototype.slice.apply(arguments);  (0) 2017.01.04
javascript module에 관한 좋은 글 소개  (0) 2016.12.26
jqgrid custom editrules 추가하기  (0) 2016.12.19
Object에 동적으로 Property 추가  (0) 2016.12.19