Object oriented - classes

Hi i am not sure why we this occurs:


return value;


For what purpose is the return value? What is it doing?


const MAX_PRIOR_SPELLS = 13;

class Wand {

  //spells is initially an empty object in the Wand class

  //but once called, the three spells are passed in

  constructor(spells = {}) {

    //this refers to Wand

    this.casted = [];

    //copies all enumerable own properties from one or

    //more source objects to a target object.

    //It returns the target object. (copy spells to this)

    Object.assign(this, spells);

    //this refers to Wand (WHICH NOW HAS SPELLS and CASTED)

    //get is the handler (its a method for getting a property value)

    //get has the target object and the property to get

    //in this case target is "this" - which is Wand

    return new Proxy(this, {

      get: (target, property) => {

        //target[property] allows you to pass in strings into the property

        //its like target.property but more flexible because you can't pass in a string using dot method

        const value = target[property];

        if (typeof value === "function") {



        return value;




  prioriIncantatem() {

    return this.casted.slice(1, MAX_PRIOR_SPELLS + 1);


  deletrius() {

    this.casted = ["deletrius"];



//1) this is the set up. creates a new class and sets up functions for

//future instances of w

//new: 1) creates new empty object 2)sets value of "this"

//to be new empty object 3)calls the constructor method

//4) then we pass in the values into the constructor

//5) we set the this to the values we passed in: e.g.

//this.name = name; this.email=email


const w = new Wand({

  expelliarmus: function() {},

  alohomora: function() {},

  avadaKedavra: function() {}


//an instance of w (which is the new Wand class)

//the property is the spell (proxy get)




console.log(w.prioriIncantatem(), [







Look at what it’s returning, it’s not just a random value. It returns a proxy object, which is a way to modify how JS built in objects normally work. You put an object behind a proxy, and from the outside they look exactly the same, but internally the proxy intercepts operations and alters how they work. That’s the point of this, it’s a spell, it’s supposed to be magic, and so it has this bizarre code to make it magic.