Sublime文本片段不适用于IIFE

时间:2016-07-06 19:44:20

标签: javascript sublimetext3 sublimetext sublimetext-snippet

我添加到Sublime Text 3的代码片段在标签触发器上不起作用,除非我删除 iife

<snippet>
    <content><![CDATA[<!doctype html>
<html>
    <head>
        <meta charset="utf-8">
        <meta name="description" content="$1">
        <meta name="viewport" content="width=device-width, initial-scale=1">
        <title>${2:Untitled}</title>
        <script src="https://code.jquery.com/jquery-2.2.4.min.js"></script>
    </head>
    <body>
        <div class="content"></div>
        <script>
            // iife
            (function($, window, document) {
                $3
            })(jQuery, window, document);
        </script>
    </body>
</html>]]></content>
    <tabTrigger>doctype</tabTrigger>
    <description>HTML - HTML foundation</description>
    <scope>text.html</scope>
</snippet>

1 个答案:

答案 0 :(得分:1)

解决方案是在美元符号上添加反斜杠:

(function(\$, window, document) {
    $3
})(jQuery, window, document);

对于关于生命的困惑感到抱歉: https://en.wikipedia.org/wiki/Immediately-invoked_function_expression