CoffeeScript: Using instanceof vs Class.constructor.name
问题 If I have a class: class Haha constructor: (@lolAmount = 1) -> alert @lolAmount And I want to check if an object is of the right class, Is it always safe to use constructor.name : haha = new Haha() unless haha.constructor.name is 'Haha' throw Error 'Wrong type' or is it better to use instanceof : haha = new Haha() unless haha instanceof Haha throw Error 'Wrong type' One argument I have for instanceof is when using extends : class BigHaha extends Haha bigHaha = new BigHaha console.log bigHaha