const obj = {
a: 27
}
const obj2 = {
a: 27
}
console.log(obj === obj2) // false
주로 데이터베이스 연결 모듈 등에 많이 쓰임
장점
단점
const num = new Object(42)
const str = new Object('abc')
num.constructor.name // Number
str.constructor.name // String
// make a class of coffee(latte, espresso)
class Latte {
constructor() {
this.name = "latte"
}
}
class Espresso {
constructor() {
this.name = "espresso"
}
}
// make a sub class => specific content
class LatteFactory {
static createCoffee() {
return new Latte()
}
}
class EspressoFactory {
static createCoffee() {
return new Espresso()
}
}
const factoryList = { LatteFactory, EspressoFactory }
// make a super class => build a frame
class CoffeeFactory {
static createCoffee(type) { // static methods => It can be called without creating an object based on the class, and memory allocation for that method can only be made once.
const factory = factoryList[type]
return factory.createCoffee()
}
}
const main = () => {
// order latte
const coffee = CoffeeFactory.createCoffee('LatteFactory')
// call coffee name
console.log(coffee.name) // latte
}
main()
const passport = require('passport')
const LocalStrategy = require('passport-local').Strategy
passport.use(new LocalStrategy(
function(username, password, done) {
User.findOne({ username }, function(err, user) {
if (err) return done(err)
if (!user) return done(null, false, { message: 'Incorrect username.' })
if (!user.validPassword(password)) return done(null, false, { message: 'Incorrect password.' })
return done(null, user)
})
}
))
=> // todo: 전반적으로 js에서 패턴을 어떻게 활용하는지 보충하면 좋을 거 같음
예전에 작성한 싱글톤 패턴 포스팅 첨부!
https://velog.io/@june_summer/디자인-패턴-싱글톤-패턴