Reputation: 19
Given the class:
class Day {
constructor(year, month, day) {
this._moment = new Moment()
this.year = year || this._moment.year()
this.month = month || this._moment.month()
this.day = day || this._moment.date()
}
}
I have let day = new Day()
and pass that through a couple function calls.
But later I check this object with day instanceof Day
and it returns false.
When I console.log(day)
in chrome I get Day {_moment: Moment, year: 2016, month: 9, day: 17}
.
With having the prefix of Day in the console log just before I check with instanceof cannot figure out why day instanceof Day
is returning false.
Any ideas?
edit:
console.log('Day: ', day)
console.log('Day: ', typeof day)
console.log('Day: ', day instanceof Day)
Output:
Day: Day {_moment: Moment, year: 2016, month: 9, day: 17}
_moment: Moment
day: 17
month: 9
year: 2016
__proto__: Object(anonymous function)
Day: object
Day: false
Upvotes: 0
Views: 536
Reputation: 2127
@Bergi was correct, in one import of the Day class I wrote: import Day from '../lib/Day'
Webpack then generated another type of Day that was being used in that part of my codebase. Tip: always use lower case string on imports and require.
Upvotes: 2