Last active
March 1, 2018 23:48
-
-
Save McTwist/56853ab0f98f2fe00dbcdbe3a6ee9f59 to your computer and use it in GitHub Desktop.
Clones an object
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Clone current object | |
function SimObject::clone(%this, %name) | |
{ | |
%this = %this.getID(); | |
%oldName = %this.getName(); | |
%name = %name !$= "" ? %name : %oldName; | |
%this.setName(__CLONE_OBJECT__); | |
%obj = new (%this.getClassName())(%name : __CLONE_OBJECT__); | |
%this.setName(%oldName); | |
return %obj; | |
} |
I had no idea that you could do it like that. I also was not aware that the first variable could send in the name as well. That is indeed interesting and useful. I will modify mine according to your directions.
Edit: I also made it cleaner and added so you can change the name of the object at the same time.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Avoid eval at all costs :)