not-composition.js

Home   »   not-composition.js

const rectangular = (state) => {
  return {
    area: () => {
      return state.height * state.width;
    }
  };
};

const openable = (state) => {
  return {
    toggleOpen: () => {
      state.open = !state.open
    }
  }
};

const buildRectangleWindow = (state) => {
  return Object.assign(state, rectangular(state), openable(state));
};

const rectangleWindow = buildRectangleWindow({
  height: 20,
  widht: 20,
  open: false
});

rectangleWindow.open;
rectangleWindow.toggleOpen();
rectangleWindow.open;

// https://www.udemy.com/course/typescript-the-complete-developers-guide/learn/lecture/15066838#notes

Leave a Reply

Your email address will not be published. Required fields are marked *