meaning of #scope in sproutcore - javascript

I'm using sproutcore, and I use sc-gen to generate a controller like this (this is from the sproutcore Todos tutorial):
sc-gen controller Todos.tasksController SC.ArrayController
In the generated javascript file, I find this javascript comment line:
/** #scope Todos.tasksController.prototype */
I wonder what this #scope does. Is this necessary? What tool is parsing this #scope keyword? Is this something specific to sproutcore or is this used in javascript in general?

SproutCore supports the JSDoc standard for generated documentation.
The #scope syntax is part of this. There is a more in-depth explanation here:
http://code.google.com/p/jsdoc-toolkit/wiki/DocExamples#Changing_Scope
It is not necessary for your own code, if you don't intend on using JSDoc. But if you do, or you are using an editor/IDE that supports JSDoc (e.g. JetBrains WebStorm), then it's a good idea to keep it in.
When building your SC app, all comments are removed (in minification), so it won't hurt the size of your app.

Related

TypeScript/JavaScript in Angular

I'm a beginner level in writing in TypeScript and working with Angular, but I am experienced in JavaScript. From what I've read, any TypeScript would be translated into JavaScript and compiled. So when I code in the TypeScript file (e.g. the whatever.component.ts file), does that mean I can mix or introduce JavaScript language code inside where I also write TypeScript in the .ts file?
How does this all exist within the .ts file in regards to a code readability aspect for someone who is just learning TypeScript/Angular?
You can of course use JavaScript anyhow you like it. However, TypeScript is built to help the developers maintaining projects by using variables types. The types can then easily be read and previewed by good IDE with the appropriate extensions.
Get used to adding types. Use interfaces for custom objects, embrace the Angular way and you will forget you ever had to deal with JavaScript very soon.
A good base for productive IDE would be Visual Studio Code with the Angular Essentials extension.
Welcome to the Angular community!

Reflect.js, What is it?

Github repo says:
Implementation of Mozilla's Parser API in JavaScript. There are few examples on github and mozilla's reference link. I have seen this library being used in one of Angular 2 seed project as well.
But what is the use of this library? Can someone explain in easy words to elaborate purpose/advantage of this library.
Thanks
It is literally just a javascript shell, much like node you can use it to write JS interactively in the shell or run JS files with it.
SpiderMonkey is Mozilla's JavaScript engine written in C/C++.
Parser, is a JS API version of that, you can use it to write tools that manipulate JS files, like a linter or compiler.
Reflect is a super old version of that which, as far as I know, is not a viable option given the other tools we have today. Note that the repo was last updated in 2012, and the JS is only ES3 compliant.

WebStorm JavaScript code completion: difference between TypeScript community stubs and official libraries

I'm new to developing with WebStorm and don't understand the difference between adding an original library with a global scope (e.g. jquery.js) either from the local file system or by downloading it via the Download button (from the Official libraries list) and adding a so-called TypeScript community stub for jquery (all via Settings... -> Languages & Frameworks -> JavaScript -> Libraries). Both give me code completion, but what is the difference and what is preferable?
And why TypeScript when we are dealing with JavaScript only?
You can use either of them, there is no principal difference. Typescript stubs are definition files for popular javascript libraries and frameworks. Please see http://blog.jetbrains.com/webstorm/2014/07/how-webstorm-works-completion-for-javascript-libraries/ - you may find this blog post helpful

VIM Semantic JavaScript completion with YouCompleteMe?

is there any way to get semantic javascript code completion in VIM?
I've tried YouCompleteMe (YCM) and it gives me some code completion, however it is purely based upon my current buffer (or buffers?).
When I explicitly call :YcmCompleter, I get
ValueError: No semantic completer exists for filetypes: ['javascript']
I'm mostly working in node:sails.js and angularjs. I'd really appreciate a way of getting library methods suggested while typing (e.g. for angular, protractor / mocha / jasmine).
Thanks!
From YCm's huge README:
YCM will use your omnifunc (see :h omnifunc in Vim) as a source for semantic completions if it does not have a native semantic completion engine for your file's filetype. Vim comes with okayish omnifuncs for various languages like Ruby, PHP etc. It depends on the language.
Tern for Vim provides the kind of completion you are looking for via Vim's native omni-completion (<C-x><C-o>). With that plugin installed, YCM should be able to use it transparently for JavaScript completion.
These answers being very outdated, and since I've struggle a little bit with it, here is an update:
Javascript semantic support in Vim with YouCompleteMe is now supported via TSServer engine as explained in Ycm's HUGE readme
I've got the information thanks to : https://medium.com/parallel-thinking/actually-great-vim-javascript-completion-eaefa1cb443d
At the moment there is no semantic completer for javascript available in YouCompleteMe. However, people are working on that. Here is the pending pull request for integrating JS Tern.
Without semantic completer available you are indeed limited to language agnostic completers, such as the identifier completer, filepath completer and snippet completer.
UPDATE: Tern has been integrated into YCM

How do you attach JSdoc in Eclipse so that I can have autocomplete for a personal library

I have a JavaScript library that I am working on currently. I have structured it into lots of files and I use the module approach to define each 'module'.
var ns = generateNamespace("me.mycompany.mypackage.MyFile");
(function (ns, undefined) {
// some module
}(ns));
The modules are dynamically named using a namespacing function meaning that autocomplete is almost impossible as things stand (unless Eclipse can run my code and figure out the namespaces, Visual Studio can!).
Therefore I intend to generate JSdoc for my project in the hope that if I include this into Eclipse (somehow) Eclipse can use this to give me content assist.
Firstly I do not know if this is possible... however I think that it is as I can see that it is maybe how this works? However I tried to follow this along and struggled to get something working, by this I mean it didn't work. The interesting info from the link:
"JSDT libraries are collections of JavaScript source files that have prototyped object/class definitions and JSDoc. The inference engine then models these libraries... making them available to every JavaScript file in the project... Bindings for nonstandard and future runtimes are similarly easy to create... add the... library to their project and gain content completion and hover help"
I know how to write JSdoc annotations and I know how to generate JSdoc using one of the various tools.
What I need therefore is instructions on how to include JSdoc (as a library maybe) in Eclipse so that it will give auto complete for the stuff in the JSdoc.
Previous answer:
You can also run jsdoc_toolkit from within eclipse by setting up Run -
> External Tools -> Open External Tools Dialog...
Location
C:\Program Files\Java\jre1.5.0_12\bin\java.exe
Working Directory
C:\DirectoryToWhereJsDocToolkitIsLocated\jsdoc_toolkit
Arguments
-jar app/js.jar app/run.js -r=4 -t=templates/htm "-d=C:
\PathToWhereDocIsSaved" "C:\PathToWebsiteToDocument"
For more about the arguments check the jsdoc_toolkit documentation.
Have fun
Simon
Taken from this Google Groups thread.
Updated Answer:
Eclipse JavaScript Editor: content assist for js files, autocompletion
Disclaimer, I'm the author of tern.java.
I suggest you that you install tern.java. It provides a JSDoc support. Once you have selected this support, you can benefit
with completion :
and soon with validation:
This support is not perfect but it starts working.
I am not using it by myself, so I'm not sure if it works, but there exists a grunt-plugin for jsdoc3. Grunt is supported by Eclipse. So maybe it helps.
Grunt-PlugIn in npm

Categories

Resources