객체.method:{fuctionName: fuction( ){ }}

BABY CAT·2022년 9월 28일
0

HTML, CSS, JavaScript

목록 보기
9/23

객체 챕터에서 배운 메쏘드 펑션

객체 마리아 안의 속성과 메쏘드
const maria = {
    name: '마리아',         // 속성
    age: 24, 
    gender: '여자',
    intro: function() {     // 메쏘드
        console.log(`저는 ${this.name}이고, 나이는 ${this.age}이며, ${this.gender}입니다.`);
    }
};

node.js의 모듈익스포츠에서

module.exports = {
   //1 걸그룹 리스트 조회
   //gid 걸그룹이름 데뷔일 히트곡명
//완료
   getGroupList: function(callback) {
      const conn = this.getConnection();
      const sql = `
      SELECT   girl_group.gid, girl_group.name, date_format(girl_group.debut, '%Y-%m-%d' ) as debut, song.title
      FROM song
      JOIN girl_group
      ON song.sid = girl_group.hit_song_id;
      `;
      conn.query(sql, (err, rows, fields) => {
         
         if (err)
               throw err;
         callback(rows);      
         
      });
      conn.end();
   }
   };

여기서 getGroupList: function(callback) {} 는
module.exports 객체안의 메쏘드다 (즉 js문법)

0개의 댓글