Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR JAVASCRIPT

javascript factory functions

const personFactory = (name, age) => {
  const sayHello = () => console.log('hello!');
  return { name, age, sayHello };
};

const jeff = personFactory('jeff', 27);

console.log(jeff.name); // 'jeff'

jeff.sayHello(); // calls the function and logs 'hello!'
Source by www.theodinproject.com #
 
PREVIOUS NEXT
Tagged: #javascript #factory #functions
ADD COMMENT
Topic
Name
3+7 =