# Class.isClass

**URL:** <https://es.discourse.group/t/class-isclass/761>\
**Category:** 💡 Ideas\
**Tags:** proposal\
**Created:** [May 4, 2021, 12:18am UTC](https://es.discourse.group/t/class-isclass/761 "2021-05-04T00:18:54Z")\
**Posts on this page:** 9\
**Page:** 2

<div class="post-metadata">

**Author:** ![theScottyJam](https://yyz2.discourse-cdn.com/free1/user_avatar/es.discourse.group/thescottyjam/32/616_2.png) [@theScottyJam](https://es.discourse.group/u/theScottyJam)\
**Post date:** [May 5, 2021, 5:56pm UTC](https://es.discourse.group/t/class-isclass/761/21 "2021-05-05T17:56:58Z")

</div>

I think the point here is that having a class.isClass() function that didn't recognize normal functions as classes would be very similar to having a Function.isFunction() that only recognized arrow functions as functions, and returned false for anything else. This would just be confusing and inaccurate.

The "old way" for classes is just as obsolete as the "old way" for functions. Neither is deprecated, and both are still widely in use today. There's use cases for all of these. So, we must recognize both kinds of functions as functions, and we must recognize both kinds of classes as classes.

---

<div class="post-metadata">

**Author:** ![Matias](https://avatars.discourse-cdn.com/v4/letter/m/7ea924/32.png) [@Matias](https://es.discourse.group/u/Matias)\
**Post date:** [May 5, 2021, 5:57pm UTC](https://es.discourse.group/t/class-isclass/761/22 "2021-05-05T17:57:11Z")

</div>

calm down ;), I didn't want to hurt your feelings ;)  
let me ask you a short question:  
If you had to start a project today, would you do it with the es6 syntax or the old way?

---

<div class="post-metadata">

**Author:** ![ljharb](https://yyz2.discourse-cdn.com/free1/user_avatar/es.discourse.group/ljharb/32/8_2.png) [@ljharb](https://es.discourse.group/u/ljharb)\
**Post date:** [May 5, 2021, 6:13pm UTC](https://es.discourse.group/t/class-isclass/761/23 "2021-05-05T18:13:41Z")

</div>

Of course I’d use the new syntax - but I’d expect to be handed normal functions too, because “other code” exists.

---

<div class="post-metadata">

**Author:** ![Matias](https://avatars.discourse-cdn.com/v4/letter/m/7ea924/32.png) [@Matias](https://es.discourse.group/u/Matias)\
**Post date:** [May 5, 2021, 6:16pm UTC](https://es.discourse.group/t/class-isclass/761/24 "2021-05-05T18:16:46Z")

</div>

it is not necessary to look good with God and with the devil ;)

---

<div class="post-metadata">

**Author:** ![theScottyJam](https://yyz2.discourse-cdn.com/free1/user_avatar/es.discourse.group/thescottyjam/32/616_2.png) [@theScottyJam](https://es.discourse.group/u/theScottyJam)\
**Post date:** [May 5, 2021, 6:27pm UTC](https://es.discourse.group/t/class-isclass/761/25 "2021-05-05T18:27:36Z")

</div>

Well, the two options are:

- We treat old-style classes for what they are - classes. es6 classes and old-style classes should be completely interchangeable, as that's how es6 classes were designed to be. I should be able to call a function that takes a class as an argument and provide it with any valid javascript class.
- We deprecate old-style classes and discourage their use, that way the only "real" classes that are left are es6 classes.

We can't just start designing APIs that don't function properly with old-style classes without deprecating them. There's really no in-between option here. And Javascript does not deprecate lightly.

---

<div class="post-metadata">

**Author:** ![Matias](https://avatars.discourse-cdn.com/v4/letter/m/7ea924/32.png) [@Matias](https://es.discourse.group/u/Matias)\
**Post date:** [May 5, 2021, 6:33pm UTC](https://es.discourse.group/t/class-isclass/761/26 "2021-05-05T18:33:53Z")

</div>

yes, i agree with you,  
but, again, my proporsal is to add the Class.isClass, and it is resolved inside the "magic" of the browser, maybe these kids can make it compatible with es6 or the old way funcion, its not our field.

---

<div class="post-metadata">

**Author:** ![theScottyJam](https://yyz2.discourse-cdn.com/free1/user_avatar/es.discourse.group/thescottyjam/32/616_2.png) [@theScottyJam](https://es.discourse.group/u/theScottyJam)\
**Post date:** [May 5, 2021, 6:39pm UTC](https://es.discourse.group/t/class-isclass/761/27 "2021-05-05T18:39:15Z")

</div>

But, that's the issue. In the old-style of classes, you don't make a class, you make a function that's intended to be used as a class. The users of the function "new" it and treat it as a class. Nowhere in the code do you specifically say that "This is a class".

e.g. This is a valid class:

```javascript
function MyClass() {}

```

In fact, in a very real sense, all functions are valid classes, we just choose not to use "new" on them to instantiate them. Many functions would behave oddly if we attempted to do so, some will throw an error, etc.

This is why @claudepache's suggestion to just check if something is a function makes a lot of sense. This is also why it's impossible for Javascript to distinguish functions from classes - because functions _are_ classes.

---

<div class="post-metadata">

**Author:** ![bergus](https://yyz2.discourse-cdn.com/free1/user_avatar/es.discourse.group/bergus/32/152_2.png) [@bergus](https://es.discourse.group/u/bergus)\
**Post date:** [May 5, 2021, 7:59pm UTC](https://es.discourse.group/t/class-isclass/761/33 "2021-05-05T19:59:00Z")

</div>

One would use the newer, more concise syntax of course. But one needs to recognise that it's just that, a _syntax_, and still the same old constructor+prototype=class pattern. There is no semantic difference, and there shouldn't be.

---

<div class="post-metadata">

**Author:** ![bergus](https://yyz2.discourse-cdn.com/free1/user_avatar/es.discourse.group/bergus/32/152_2.png) [@bergus](https://es.discourse.group/u/bergus)\
**Post date:** [May 5, 2021, 8:00pm UTC](https://es.discourse.group/t/class-isclass/761/35 "2021-05-05T20:00:16Z")

</div>

I disagree. The protocol is actually the cleanest solution to your problem.

[Previous page](https://es.discourse.group/t/class-isclass/761.md?page=1)
