# Extending Cesium classes

**URL:** <https://community.cesium.com/t/extending-cesium-classes/7371>\
**Category:** CesiumJS\
**Created:** [August 31, 2018, 5:47pm UTC](https://community.cesium.com/t/extending-cesium-classes/7371 "2018-08-31T17:47:26Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![david](https://sea2.discourse-cdn.com/cesium/user_avatar/community.cesium.com/david/32/3484_2.png) [@david](https://community.cesium.com/u/david)\
**Post date:** [August 31, 2018, 5:47pm UTC](https://community.cesium.com/t/extending-cesium-classes/7371/1 "2018-08-31T17:47:26Z")

</div>

Just wondering if there is another way I haven't come across yet to easily extend the base Cesium classes to add new functionality. For instance, if I wanted to make a custom class called MyEntity that extends the base Entity class, can I do that?

I've tested doing this. I accept the object that would be used to create the entity as a parameter in my class and then pass it to the super() call to create the Cesium Entity. All that seems to work but when I attempt to add my new MyEntity object to the viewer I get an error that name is a reserved keyword.

I've gotten this to work with another class or two but Entity seems to be giving me trouble. Is there something stupid I'm missing?

---

<div class="post-metadata">

**Author:** ![omar](https://sea2.discourse-cdn.com/cesium/user_avatar/community.cesium.com/omar/32/1999_2.png) [@omar](https://community.cesium.com/u/omar)\
**Post date:** [September 1, 2018, 5:35pm UTC](https://community.cesium.com/t/extending-cesium-classes/7371/2 "2018-09-01T17:35:03Z")

</div>

Can you post some of your code?

I just tried this out with the examples described here [https://kevhuang.com/subclasses-and-inheritance-in-javascript/](https://kevhuang.com/subclasses-and-inheritance-in-javascript/) and this creates a “MyEntity” that will add a default red material to a rectangle:

var MyEntity = function(options) {  
if (options && options.rectangle) {  
options.rectangle.material = Cesium.Color.RED.withAlpha(0.5);  
}

```
Cesium.Entity.call(this, options);

```

};  
MyEntity.prototype = Object.create(Cesium.Entity.prototype);  
MyEntity.prototype.constructor = MyEntity;

``

Here’s a[full example on Sandcastle](http://localhost:8080/Apps/Sandcastle/index.html#c=rZPLbtswEEV/hdAioQFnZKcIUDSK0cLJrkWANOhKG5oa22wpjkBSNpTC/15Sr8rxposK0IPkvTNHl9JBWHZQeETLHpjBI1ujU3UJP9o5fi3b4ZqMF8qgvZ7d5yY3h+D61jwZr3wTfNvaSK/IcKrizc3Yb8Zyw8KhtmyYZVdXrH8Ei9ILs9MYpJ0wHherUAqPVgkdmvRga9Jk4eXpEY7K77/oai/4Au4iVyxxinjxoZd3jCCF1tzvlZsPTaLhFM7hNaCy5Mk3FYZez5ufAQGkxdCfn5cadbP7+JKXfpChvLe19BRDHQStuotO1s5TOcYXYx9UvI9jjIB9miYkiWyhTKByYaEHexnj2loqH3FnER2/WS4XsJizD+315mM3uIPFbD5GdYopdNsPGPsrdCCKgk8J/265IVsKfcZ9ls3/h7+dwt/+I/wUs4fvVG9E5Svxd54oSeZJ5nyjcdWV/6zKiqxntdUcIPVYVjpyp5ta/sLwZbjWlqWDKSvUganiIU/e/TF5wqQWzoWVba31d/WGebLK0qA/s2kSIZvd8wGtFk2U7Jerr90kAGRpGF66PJHeCDup+Ac). Let me know if that helps!

---

<div class="post-metadata">

**Author:** ![david](https://sea2.discourse-cdn.com/cesium/user_avatar/community.cesium.com/david/32/3484_2.png) [@david](https://community.cesium.com/u/david)\
**Post date:** [September 6, 2018, 1:17am UTC](https://community.cesium.com/t/extending-cesium-classes/7371/3 "2018-09-06T01:17:10Z")

</div>

I mean yeah, that can work. I was hoping to use the cleaner, class implementation where I could do..

class MyEntity extends Cesium.Entity {  
&nbsp;&nbsp;&nbsp;constructor() {  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;super()  
&nbsp;&nbsp;&nbsp;}  
}

And define things from there but I guess I could go ahead and just extend it using the prototype.

Thanks

---

<div class="post-metadata">

**Author:** ![omar](https://sea2.discourse-cdn.com/cesium/user_avatar/community.cesium.com/omar/32/1999_2.png) [@omar](https://community.cesium.com/u/omar)\
**Post date:** [September 11, 2018, 5:18pm UTC](https://community.cesium.com/t/extending-cesium-classes/7371/4 "2018-09-11T17:18:33Z")

</div>

That would definitely be nice, and in fact is on our roadmap, see [https://github.com/AnalyticalGraphicsInc/cesium/issues/2524#issuecomment-363495391](https://github.com/AnalyticalGraphicsInc/cesium/issues/2524#issuecomment-363495391)
