Answers for "factory function"

2

factory function

function createPerson(firstName, lastName) {
    return {
        firstName: firstName,
        lastName: lastName,
        getFullName() {
            return firstName + ' ' + lastName;
        }
    }
}
Code language: JavaScript (javascript)
Posted by: Guest on September-14-2021
0

function(global factory)

// Standard UMD format
/*  |------------------|       |------------------|
    |                  v       v                  |
    |    (function (global, factory) {            |
    |                                             |
    |                                             |
    |        /* deleted for clarity */      /*    |*/
/*  |                 |---------------------------|
    |                 |
    |    }(this, function () { 'use strict';
    |       |
    |-------|
             /* So, global is window scope (which exports the function as a variable),
             and factory implements the module as a function.*/

/*       });*/
Posted by: Guest on August-08-2020
0

factory functions

const Person = (name) => {
  const sayName = () => console.log(`my name is ${name}`)
  return {sayName}
}

const Nerd = (name) => {
  // simply create a person and pull out the sayName function with destructuring assignment syntax!
  const {sayName} = Person(name)
  const doSomethingNerdy = () => console.log('nerd stuff')
  return {sayName, doSomethingNerdy}
}

const jeff = Nerd('jeff')

jeff.sayName() //my name is jeff
jeff.doSomethingNerdy() // nerd stuff
Posted by: Guest on October-11-2021

Code answers related to "factory function"

Browse Popular Code Answers by Language