add getAttribute + test

pull/14/head
Bastien JACQUELIN 2 years ago
parent d6774300aa
commit 7857f56201

@ -1,12 +1,11 @@
/*var fs = require("fs") // import { Card5 } from "../Model/Card5";
var vm = require('vm') // import('../Model/Card5');
//import {Card} from '../Model/Card';
var content = fs.readFileSync(filename)
vm.runInThisContext(content)
*/
console.log("~#Test#~"); console.log("~#Test#~");
let card4 = new Card('red','2','losange','full'); let card4 = new Card('red','2','losange','full');
console.log(`carte de 4 elements : ${card4.color}`); console.log(`carte de 4 elements : ${card4.color}`);
let card5 = new Card5('blue','2','losange','full','pointillet'); let card5 = new Card5('blue','2','losange','full','pointillet');
console.log(`carte de 5 elements : ${card5.outline}`); console.log(`carte de 5 elements : ${card5.outline}`);
console.log(`carte de 5 elements : ${card5 instanceof Card5}`); console.log(`carte de 5 éléments instance de 5: ${card5 instanceof Card5}`);
console.log(`carte de 5 éléments accès par méthode : ${card5.getAttributes()[0]}`);

@ -5,5 +5,17 @@ class Card{
this.shape=shape; this.shape=shape;
this.filling=filling; this.filling=filling;
} }
/**
* @returns array of all attributes :
idx 1 : color
idx 2 : number
idx 3 : shape
idx 4 : filling
idx 5 : null
* @author Bastien Jacquelin
*/
getAttributes(){
return [this.color,this.number,this.shape,this.filling,null];
} }
}//export {Card}

@ -1,9 +1,21 @@
// import('.Card');
class Card5 extends Card { class Card5 extends Card {
constructor(color, number, shape, filling, outline){ constructor(color, number, shape, filling, outline){
super(color,number,shape,filling); super(color,number,shape,filling);
this.outline=outline; this.outline=outline;
} }
arrayOfAttributes(){ /**
* @returns array of all attributes :
idx 1 : color
idx 2 : number
idx 3 : shape
idx 4 : filling
idx 5 : outline
* @author Bastien Jacquelin
*/
getAttributes(){
return [this.color,this.number,this.shape,this.filling,this.outline];
} }
} }
// export {Card5};
Loading…
Cancel
Save