Search
 
SCRIPT & CODE EXAMPLE
 

JAVASCRIPT

factory function

function createPerson(firstName, lastName) {
    return {
        firstName: firstName,
        lastName: lastName,
        getFullName() {
            return firstName + ' ' + lastName;
        }
    }
}
Code language: JavaScript (javascript)
Comment

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!'
Comment

factory function in javascript

let john = {
    firstName: 'John',
    lastName: 'Doe',
    getFullName() {
        return this.firstName + ' ' + this.lastName;
    }
};

console.log(john.getFullName());
Code language: JavaScript (javascript)
Comment

PREVIOUS NEXT
Code Example
Javascript :: jquery.slim.min.js 
Javascript :: jest write test for function 
Javascript :: ejs layout 
Javascript :: Iterate with JavaScript Do...While Loops 
Javascript :: merge two binary tree 
Javascript :: ways to open modal in angular 
Javascript :: react native spinkit 
Javascript :: angular $http abort request 
Javascript :: nodemon writefilesync restart problem 
Javascript :: fibonacci recursive method 
Javascript :: js get location params 
Javascript :: find vowels in string javascript 
Javascript :: inline styling js 
Javascript :: list of string angular 
Javascript :: math.floor + roandom 
Javascript :: Node Sass does not yet support your current environment: OS X 64-bit with Unsupported runtime in cypress tests 
Javascript :: rails json schema validation 
Javascript :: javascript Symbol Methods 
Javascript :: click tester 
Javascript :: how to select default searchable dropdown value in jquery 
Javascript :: mongodb mongoose update delete key 
Javascript :: display json data in html table react 
Javascript :: how to get time zone difference date-fns 
Javascript :: shopify routes 
Javascript :: react functional component example 
Javascript :: javascript set() method 
Javascript :: rxjs takeuntil 
Javascript :: iterating over a string 
Javascript :: Movie-app using react 
Javascript :: what is middleware in express js 
ADD CONTENT
Topic
Content
Source link
Name
2+6 =