Are built in objects in JavaScript like Math, Array, String etc... just defined in a .js file and then compiled and or interpreted? Can I get a basic high level overview of how they are implemented and made available? I see that in Java there is a String class and that class gets compiled and is available when I need to create an object, is JavaScript similar?
Thank You.
Related
I am trying to use some functions from a code that has been obfuscated. So i have an html file that is calling a JS file thru the tag:
<script src="gwt_svg_viewer/gwt_svg_viewer.nocache.js"></script>
that file is defining a function called "onScriptdownloaded" which receives a string like this:
gwt_svg_viewer.onScriptDownloaded(["var $wnd = window.parent;function RE(){}"]);
So my question is how can i access to RE? in another JS file?
It seems that there was a kind of GWT code implemented, but i am not really familiar with that.
Variable names and functions in gwt will be obfuscated every time you compile your project, and variables and functions will be renamed in the process, in order to call a gwt code from javascript in a consistence manner you will need to use jsinterop to export java types. more information can be found in the gwt jsinterop documentation
I am learning package:js and the dart file, which is a dart wrapper for chart.js.
I think this file is a bridge which connects dart and javascript. So, in this file, it must tell what javascript library this dart file is trying to connect. Am I right? But I did not find it.
What do the following statements mean? Do the following two statements tell what javascript library this dart file is trying to connect?
#JS('Chart')
library chart.js;
I have no idea how to map functions https://github.com/google/chartjs.dart/blob/master/lib/chartjs.dart to functions in https://cdnjs.cloudflare.com/ajax/libs/Chart.js/2.6.0/Chart.js. Anyone can give more tutorials?
You don't need to map to a JavaScript file, you just need to map to JS objects and functions.
You need to add a script tag to index.html that loads the JavaScript file you want to map to, this will make it available globally.
You then need to map
Dart functions to JavaScript functions, so when you call such a Dart function the call will actually be forwarded to the JavaScript function.
Dart classes so that you can use strongly typed Dart classes which will then be converted to and from JavaScript objects when you for example pass them as parameters to mapped functions or get them as return values from such function calls.
#JS('Chart')
library chart.js;
The name chart.js after library is arbitrary. The library directive just needs an unique name.
#JS('Chart') means that the loaded chart.js library is available in JavaScript land under window.Chart (window means global in JS land and is implicit).
#JS()
class Chart {
declares a Dart class Chart and #JS() maps it to a JS class with the same name in the library scope declared above. So the Dart class Chart will map to the JavaScript class window.Chart.Chart.
external factory Chart(
The external ... declarations inside the Dart Chart class map to the JS methods with the same name.
More details can be found in the README.md https://pub.dartlang.org/packages/js.
If you're still stuck you can ask more concrete questions. It's difficult to answer generic questions about how to use a package.
I am using C# to create a rather complicated data object that contains a couple of lists of objects that is then serialized and sent to the client. I like this approach a lot because I am using the same object definition in both my client and server side code.
I'd like to create some sort of reference file for Visual Studio 2012 so that intellisense can help me out, typos in my javascript code seem to be my biggest problem in debugging.
Does anybody have any tips for doing this? I understand that as I add new properties to the C# class I will need to refresh this reference file.
You can use T4 template to generate javascipt viewmodel file from your C# class.
Take a look at this article.
Also some more information available.
I'm using Google Closure Template in order to write my application's UI using JavaScript. Look at this question for the detailed reason of why I'm using Google Closure Template. I want it to be multilingual. I see that there is a --locales switch and also looked at the samples provided in the project here and here. In the README_FOR_EXAMPLES files it is written that
+ simple_generated_en.js, features_generated_en.js,
simple_generated_x-zz.js, features_generated_x-zz.js
The JS files generated by SoyToJsSrcCompiler when it is executed
on simple.soy and features.soy (locales are 'en' and 'x-zz' with the translated XLIFF files from shared examples directory 'examples' and with the above compile-time globals
file). We need both simple.soy and features.soy because some of the templates in features.soy call the templates in simple.soy.
Note: For an example Ant target (and command line args) that
generates these files, please see target 'js-features-example' within the top-level 'build.xml'.
What I expected was that it would generate just one JavaScript code base which will use desired strings from the appropriate locale file based on an option provided at runtime before the template function is called. Is that possible with closure templates?
As far as I can see, you can use a dictionary-object as a parametr for your template.
/**
* #param dict
*/
{template .example}
<h1>{$dict.title}</h1>
<div>{$dict.content}</div>
{/template}
This object can be generated on the server-side from your locale file and transfered to javascript via script tag.
Otherwise you can load different compiled template file to the client side according to the locale.
There's also i18n possibility, but it's kinda useless for your problem, imo.
so I was looking at a project and I noted that they had a templating system set up in html files, and I am not too familiar with the whole concept...But when I started browsing the code I was seeing things like: ${varName} which upon execution were being substituted for names out of an nls file which I assume is intended to allow for multiple languages.
I know for a fact that the templating file does not get parsed by a php engine, so I am thinking that maybe the syntax is some type of shorthand for server-side javascript. Which has me intrigued, does anyone have any ideas as to how they are accomplishing this substitution? I cant seem to find info on this in any google search I could think of, so any hints would be helpful.
If you are looking at code which extends dijit._Templated and references a file or an inline string with this syntax, it's being parsed client side. The references are variable names on the widget JS object, which can be set up to point at strings from a localized string bundle with dojo.i18n