Méthode 1

avec prototype

function Name(first, last) {
    this.first = first;
    this.last = last;
}

Name.prototype = {
    get fullName() {
        return this.first + " " + this.last;
    },

    set fullName(name) {
        var names = name.split(" ");
        this.first = names[0];
	    this.last = names[1];
    }
};
let n = new Name(); // on crée l'objet
n.fullName = "Thomas Guesnon" // là, c'est le setter
console.log(n.fullName) // là, c'est le getter
// > Thomas Guesnon
console.log(n.first)
// > Thomas
console.log(n.last)
// > Guesnon

Méthode 2

avec fonctions embarquées

function Name(first, last){
	this.first = first;
	this.last = last;
	
	this.getValue = function(){
	    return this.first + " " + this.last;
	}
	this.setValue = function(name){
		const names = name.split(" ");
        this.first = names[0];
        this.last = names[1];
	}
}
let n = new Name();
n.setValue("Thomas Guesnon");
console.log(n.getValue());
// > Thomas Guesnon
console.log(n.first);
// > Thomas
console.log(n.last);
// > Guesnon

Méthode 3

avec defineProperty

function Name(first, last){
	this.first = first;
	this.last = last;
}

Object.defineProperty( Name.prototype, "fullName", {
	get: function(){ 
		return this.first+" "+this.last 
	},
	set: function(name){
		const names = name.split(" ");
        this.first = names[0];
        this.last = names[1];
	}
});
let n = new Name();
// attention, c'est bien n.fullName = value et non pas n.fullName(value);
n.fullName = "Thomas Guesnon"; 
console.log(n.fullName);
// > Thomas Guesnon
console.log(n.first);
// > Thomas
console.log(n.last);
// > Guesnon

Méthode 4

dans une variable, w/ get et set keywords

let Name = {
	first: undefined,
	last: undefined,
	
	get fullName(){
		return this.first+" "+this.last 
	},
	set fullName(name){
		const names = name.split(" ");
        this.first = names[0];
        this.last = names[1];	
	}
}
// attention, c'est bien Name.fullName = value et non pas Name.fullName(value);
Name.fullName = "Thomas Guesnon"; 
console.log(Name.fullName);
// > Thomas Guesnon
console.log(Name.first);
// > Thomas
console.log(Name.last);
// > Guesnon

Methode 4

POO, Class

Class {toto}{
	constructor(){
	
	}
	method{
	
	}
}