[{"data":1,"prerenderedAt":179},["ShallowReactive",2],{"article-javascript-patterns-self-invocation":3},{"article":4,"tags":58,"previous":73,"next":136},{"id":5,"title":6,"author":7,"body":8,"createdAt":47,"description":48,"extension":49,"img":50,"meta":51,"navigation":52,"path":53,"seo":54,"stem":55,"tags":56,"updatedAt":47,"__hash__":57},"articles\u002Farticles\u002Fjavascript-patterns-self-invocation.md","JavaScript Patterns Self invocation","[object Object]",{"type":9,"value":10,"toc":43},"minimark",[11,19,26,29,33,36,40],[12,13,14,15,18],"p",{},"Self-invocation (also known as auto-invocation) is when a function executes immediately upon it's definition. ",[16,17],"br",{},"\nThis is a core pattern and serves as the foundation for many other patterns of JavaScript development.  A self-invoking function is a standard function, just with a set of parentheses appended to the end.",[20,21,25],"pre",{"className":22},[23,24],"brush:","javascript","     \nfunction(){  \n    var msg = \"hello\";  \n    alert(msg);  \n}();  \n",[12,27,28],{},"The above example defines an anonymous function. This creates a literal function, yet since no name is attributed to it, the value is never stored. The trailing parenthesis tell the function to execute, just as if you were calling a named function. Once the function terminates, the variables are discarded and the global object remains unchanged. It it recommended that an extra set of parentheses wrap the function definition as well so to provide a visual clue to the developer that the function isn’t a normal function.",[20,30,32],{"className":31},[23,24],"     \n(function(){  \n    var msg = \"hello\";  \n    alert(msg);  \n})();  \n  \n",[12,34,35],{},"In the event where a self-invoking function requires parameters, they can be passed in the same manor that you would a regular function",[20,37,39],{"className":38},[23,24],"     \n(function(id){  \n    var msg = \"hello\";  \n    alert(msg);  \n})('idvalue');  \n  \n",[12,41,42],{},"In an effort to protect the global object, all JavaScript applications should be written within a self-invoking function. This will create an application scope in which variables can be created without the fear of them colliding with other applications. If a global variable is needed, developers must take the extra step by setting them directly within the window object. For example window.foo = ‘bar’;. Self-invocation is a fundamental pattern of professional JavaScript development.",{"title":44,"searchDepth":45,"depth":45,"links":46},"",2,[],"2015-04-20T08:07:12.0000000-04:00","Learn about self invocation javascript patterns.","md",null,{},true,"\u002Farticles\u002Fjavascript-patterns-self-invocation",{"title":6,"description":48},"articles\u002Fjavascript-patterns-self-invocation",[24],"6mEuLpLXzvMN8rDuNWbgVGP4TND1riFnYdYRKLW0aeI",[59],{"id":60,"title":61,"body":62,"description":66,"extension":49,"img":67,"meta":68,"name":24,"navigation":52,"path":69,"seo":70,"stem":71,"__hash__":72},"tags\u002Ftags\u002Fjavascript.md","Javascript",{"type":9,"value":63,"toc":64},[],{"title":44,"searchDepth":45,"depth":45,"links":65},[],"JavaScript is a programming language adhering to the ECMAScript spec.","https:\u002F\u002Fimages.unsplash.com\u002Fphoto-1598425237654-4fc758e50a93?ixlib=rb-1.2.1&ixid=eyJhcHBfaWQiOjEyMDd9&auto=format&fit=crop&w=675&q=80",{},"\u002Ftags\u002Fjavascript",{"description":66},"tags\u002Fjavascript","wqzmOtgcvcAeeB0QinMxw2OqnSglrJN0TeWQ-fulunM",{"id":74,"title":75,"author":7,"body":76,"createdAt":125,"description":126,"extension":49,"img":127,"meta":128,"navigation":52,"path":129,"seo":130,"stem":131,"tags":132,"updatedAt":125,"__hash__":135},"articles\u002Farticles\u002Fintellisense-and-javascript-in-visual-studio-2012.md","Intellisense and JavaScript in Visual Studio 2012",{"type":9,"value":77,"toc":123},[78,81],[12,79,80],{},"In short use _references.js file with your web projects.  What is _references.js?",[12,82,83,84,88,89,91,92,94,95,91,97,99,100,91,102,104,105,91,107,109,110],{},"With the latest Visual Studio a new file _references.js is found in the scripts directory.  As you probably know, the ",[85,86,87],"code",{},"\u002F\u002F &lt;reference path=”…” \u002F&gt;"," syntax was introduced in Visual Studio long time ago to make you able to have intellisense in any JavaScript file to include everything defined in the JavaScript located at this path.  Said another way if you write the very first line in any JavaScript file, say “my-page.js”, and make sure the path points to the proper jQuery file, when you write code in “my-page.js”, you’ll get intellisense for everything in the jQuery file.",[16,90],{},"\n ",[16,93],{},"\nThe quality of the intellisense will vary based on the referenced jQuery file, whether it’s minified file (least intellisense info, only member names, sometimes), just standard source\u002Fdebug file, or even one that VsDoc comments (best intellisense, might even have notes on what types you need to pass to methods, when defined in VsDoc comments).",[16,96],{},[16,98],{},"\nVisual Studio will give you intellisense from all files that have references in the “_references.js” file. This way you can define the global \u002F common files you use all the time. This might include some library files like jQuery, or some files you use everywhere in the project like some internal utilities files.  In addition, for related files, you can use the “\u003Creference >” syntax on top of every file to connect them (from intellisense point of view).",[16,101],{},[16,103],{},"\nThere is only one _references.js file for each project and is located in the \u002Fscripts directory.",[16,106],{},[16,108],{},"\nYou can manage this file manually or in the latest Visual Studio  release you can add\u002Fedit references via Tools > Options > Text Editor –> JavaScript –> Intellisense –> References node\n",[111,112,114],"a",{"href":113},"\u002Fmedia\u002Farticulate-import\u002Fimage_6.png",[115,116],"img",{"style":117,"src":118,"border":119,"alt":120,"title":120,"width":121,"height":122},"background-image: none; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; padding-top: 0px; border: 0px;","\u002Farticles\u002Fimages\u002F\u002Fmedia\u002Farticulate-import\u002Fimage_thumb_6.png",0,"image",244,143,{"title":44,"searchDepth":45,"depth":45,"links":124},[],"2015-04-20T08:07:12.1900000-04:00","How to enable intellisense with Visual Studio and JavaScript","\u002Farticles\u002Fimages\u002Fimage_thumb_6.png",{},"\u002Farticles\u002Fintellisense-and-javascript-in-visual-studio-2012",{"title":75,"description":126},"articles\u002Fintellisense-and-javascript-in-visual-studio-2012",[133,134],"aspnet","visualstudio","oVO-9EOZCUi_NY9jWqCmtawNfh0TKJlWULh6dhsTtJY",{"id":137,"title":138,"author":7,"body":139,"createdAt":170,"description":171,"extension":49,"img":165,"meta":172,"navigation":52,"path":173,"seo":174,"stem":175,"tags":176,"updatedAt":170,"__hash__":178},"articles\u002Farticles\u002Fhow-to-delete-a-file-in-windows-with-a-too-long-filename.md","How to delete a file in Windows with a too long filename?",{"type":9,"value":140,"toc":168},[141,144,147,150,153,156],[12,142,143],{},"I came across a situation where I had to remove all files at this location C:\\Users{username}\\AppData\\Local\\Temp.",[12,145,146],{},"I was able to delete most of the files however I came across a Windows error stating that one or more files had a file name too long to be removed. I tried a number of approaches (not to be stated here) however the resolution was to use RoboCopy.",[12,148,149],{},"I created a local directory c:\\temp\\empty_dir with nothing in it.\nI then used the following RoboCopy command to mirror that empty directory with the problematic directory.",[12,151,152],{},"robocopy c:\\temp\\empty_dir C:\\Users{username}\\AppData\\Local\\Temp \u002Fs \u002Fmir",[12,154,155],{},"This works because robocopy internally uses the Unicode-aware versions of Win32 functions, with the \\?\\ prefix for file paths; those functions have a limit of 2¹⁶-1 (32,767) characters instead of 259",[12,157,158],{},[111,159,161],{"href":160},"\u002Farticles\u002Fimages\u002Fwindows-live-writer-1da1028d1d1d_11da4-robo_2.jpg",[115,162],{"title":163,"style":164,"border":119,"alt":163,"src":165,"width":166,"height":167},"robo","border-top: 0px; border-right: 0px; background-image: none; border-bottom: 0px; padding-top: 0px; padding-left: 0px; border-left: 0px; display: inline; padding-right: 0px","\u002Farticles\u002Fimages\u002Fwindows-live-writer-1da1028d1d1d_11da4-robo_thumb.jpg",240,89,{"title":44,"searchDepth":45,"depth":45,"links":169},[],"2010-01-27T13:25:31.2700000-05:00","Long file names within windows continues to be trouble and difficult to manage.",{},"\u002Farticles\u002Fhow-to-delete-a-file-in-windows-with-a-too-long-filename",{"title":138,"description":171},"articles\u002Fhow-to-delete-a-file-in-windows-with-a-too-long-filename",[177],"tools","U1_lv-0K6POEbvXcYmd2Tf8OYYciO6OT3p9TZrcrlQY",1781574764944]