Objects - Creation and the Keyword "new"
Last updated
Was this helpful?
Last updated
Was this helpful?
While Transcrypt supports standard Python syntax for class instance creation and use, the JavaScript syntax for creating new objects must be used when interacting with a small number of Screeps prototypes. In Python, new objects are created by calling the class; in JavaScript, to create an instance of an object, the new
keyword must be provided along with a call to the contruct that creates the object.
Transcrypt provides a method, __new__()
, that supports creating interacting with constructors in third party libraries. When working with code examples provided by the API, any instance of new Constructor()
should be replaced with __new__(Constructor())
.
Creating a new object:
Creating a new :
Creating a new :