Metaprogramming - sgml/signature GitHub Wiki

Emulation Layers

Custom RegExp Replacement via the Symbol API

Reflect API

Imperative vs Declarative

cfml

<Cfloop from="1" to="100" index="i">
    <Cfif i mod 15 eq 0>FizzBuzz
    <Cfelseif i mod 5 eq 0>Fizz
    <Cfelseif i mod 3 eq 0>Buzz
        <Cfelse><Cfoutput>#i# </Cfoutput>
    </Cfif>      
</Cfloop>

cfscript version

<cfscript>
    result = "";
    for(i=1;i<=100;i++){
        result=ListAppend(result, (i%15==0) ? "FizzBuzz": (i%5==0) ? "Buzz" : (i%3 eq 0)? "Fizz" : i );
    }
    WriteOutput(result);
</cfscript>

Proxy Objects

Stack Trace Customization

Examples

Java

public class ExtractCommentsDoclet {
    public static boolean start(RootDoc root) throws IOException {
        for (ClassDoc c : root.classes()) {
            print(c.qualifiedName(), c.commentText());
            for (FieldDoc f : c.fields(false)) {
                print(f.qualifiedName(), f.commentText());
            }
            for (MethodDoc m : c.methods(false)) {
                print(m.qualifiedName(), m.commentText());
                if (m.commentText() != null && m.commentText().length() > 0) {
                    for (ParamTag p : m.paramTags())
                        print(m.qualifiedName() + "@" + p.parameterName(), p.parameterComment());
                    for (Tag t : m.tags("return")) {
                        if (t.text() != null && t.text().length() > 0)
                            print(m.qualifiedName() + "@return", t.text());
                    }
                }
            }
        }
        return true;
    }

    private static void print(String name, String comment) throws IOException {
        if (comment != null && comment.length() > 0) {
            new FileWriter(name + ".txt").append(comment).close();
        }
    }
}

JavaScript

const fs = require('fs');
const extract = require('extract-comments');

fs.readFile('/path/to/your/file.js', 'utf8', function(err, data) {
  if (err) throw err;
  const comments = extract(data);
  console.log(comments);
});
⚠️ **GitHub.com Fallback** ⚠️