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 :: how to use axios filter 
Javascript :: javascript syntax of throw statement 
Javascript :: resize js 
Javascript :: javascript templates 
Javascript :: how to make and add to an array in javascript 
Javascript :: adding cors in angular 
Javascript :: javascript get the last array element 
Javascript :: get js 
Javascript :: what is cross browser testing 
Javascript :: get last item in array js 
Javascript :: console.log is not a function 
Javascript :: (this).find 
Javascript :: new line in textarea javascript 
Javascript :: vue component naming convention 
Javascript :: date time react component 
Javascript :: What do "module.exports" and "exports.methods" mean in NodeJS / Express 
Javascript :: background image react 
Javascript :: js if statement 
Javascript :: proptypes for a react component 
Javascript :: on hover event 
Javascript :: js vue array change position 
Javascript :: dockument anywhere click fucntion in js 
Javascript :: db.each store rowa 
Javascript :: binding variable with td in angular site:stackoverflow.com 
Javascript :: how to console.log while using a prompt in javascript 
Javascript :: gdscript create node 
Javascript :: generators javascript in class 
Javascript :: node alternative to btoa 
Javascript :: check if item is already registered in angular angularfire site:stackoverflow.com 
Javascript :: javascript muuttujan määrittely 
ADD CONTENT
Topic
Content
Source link
Name
6+4 =