@@ -8069,6 +8069,52 @@ Instruction
80698069 <Type >
80708070 <Name >Turtle.js</Name >
80718071 <Members >
8072+ <ScriptMethod >
8073+ <Name >ToString</Name >
8074+ <Script >
8075+ < #
8076+ .SYNOPSIS
8077+ `Turtle.js` definition
8078+ .DESCRIPTION
8079+ Our JavaScipt turtle is actually contained in a PowerShell object first.
8080+
8081+ This object has a number of properties ending with `.js`.
8082+
8083+ These are portions of the class.
8084+
8085+ To create our class, we simply join these properties together, and output a javascript object.
8086+ #>
8087+ param()
8088+
8089+
8090+
8091+ @(
8092+
8093+ # Since we are building a javascript object, we need to wrap everything in curly braces
8094+ "{
8095+ "
8096+ # Indentation does not matter to most machines, but people tend to appreciate it.
8097+ " "
8098+ @(foreach ($javaScriptProperty in $this.psobject.properties | Sort-Object Name) {
8099+ # We only want the .js properties
8100+ if ($javaScriptProperty.Name -notmatch '\.js$') { continue }
8101+ # If the property is a function, we need to handle it differently
8102+ if ($javaScriptProperty.value -match '^function.+?\(') {
8103+ # specificically, we need to remove the "function " prefix from the name
8104+ $predicate, $extra = $javaScriptProperty.value -split '\(', 2
8105+ # and then we need to reassemble it as a javascript method
8106+ $functionName = $predicate -replace 'function\s{1,}'
8107+ "${functionName}:function ($extra"
8108+ }
8109+ else {
8110+ # Otherwise, include it inline.
8111+ $javaScriptProperty.value
8112+ }
8113+
8114+ }) -join (',' + [Environment]::Newline + ' ')
8115+ "}") -join ''
8116+ </Script >
8117+ </ScriptMethod >
80728118 <NoteProperty >
80738119 <Name >forward.js</Name >
80748120 <Value >function forward(distance) {
0 commit comments