Good Javascript Cleaner [duplicate] - javascript

This question already has answers here:
Closed 11 years ago.
Possible Duplicate:
HTML formatter/tidy/beautifier for JavaScript
I'm looking for a good automated javascript cleaner (as in locates and fixes errors), similar to the w3c validator's cleaner function (that fixes the javascript errors).
Update: Thanks to a helpful responce I found my solution: Closure Linter.

Try jsbeautifier to beautify your code and jslint to clean up its syntax.

If I understand you correctly, you might be interested in Google's Closure Linter, which, like JSLint, validates your code and reports problems, but also provides the possibility to fix them:
(...) you can substitute fixjsstyle for gjslint to automatically fix many of the errors that gjslint checks for.

I quite like http://jsbeautifier.org/ for cleaning up Javascript.
This site is also mentioned in the answer provided by Matt in the comments.

Related

Colon after colon syntax while calling a function in Javascript [duplicate]

This question already has an answer here:
Colon after function declaration in javascript [duplicate]
(1 answer)
Closed 4 years ago.
I came across a syntax somewhere on the web recently and couldn't grasp its meaning.
What I understand is that when we write props: Object inside the brackets, it means we're assigning a default value to props as Object. But what does the 2nd colon signify? It looks like a key-value pair but is confusing me still.
Tried searching on the web but wasn't able to search due to lack of terminology. Any ideas what this means?
someFn(props: Object): Object {
return someOtherFn(props);
}
These are type annotations. They are not standard javascript. They are added when using tools that layer static typing onto javascript. The two most popular flavors are Typescript and Flow.
When you write code that uses this syntax you will transpile your source code into code that is syntactically valid for execution by running one of the above mentioned tools on your code. When you do, it will tell you if your usage of the types is correct, raise warnings that are helpful in development, and then strip all this out so it can actually be run.

Where can i find the code source of javascript functions? [duplicate]

This question already has answers here:
Where can I find javascript native functions source code? [duplicate]
(3 answers)
Closed 1 year ago.
For example, i want to know how the querySelector method was built. I checked on MDN but there's only examples that show how to use it.
I also tried to check in the console.log but nothing readable.
There is a non-standard method to do this. Please be aware that it is not fully cross-browser compatible and shouldn't be used in a production environment.
function hello(){
return "Hi!";
}
console.log(hello.toSource());
See https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Function/toSource for more.
Edit:
To see the source code of a built-in function, you will need to look at the engine source. This varies browser to browser. For example, Chrome uses the V8 engine. See https://github.com/v8/v8

Sandboxed JavasScript function

I'm creating an extension for Chrome (Just noraml HTML/JS). I would like to make an advanced scripting mode for users.
In a form I'll put this:
function generateString(){
//EDITABLE PART
return val;
}
if somebody for example put window.location="", nothing should happen, or if somebody put myVar=55; (previously defined in my code), it shouldn't do anything either. The only thing that I want to access is the return value.
Is this possible somehow? Googled for it and found something about putting it into a iframe, but they could still do window.location="javascript:dosomehaxing()", right?
Thanks a lot!
Since nobody posted an answer in the answer section, I'll post my findings here:
From the thread that serg commented with, the question "Is It Possible to Sandbox JavaScript Running In the Browser?", JSandbox seems to be the best, lightweight option to me. Its syntax is quite simple, too.

How to protect javascript function? [duplicate]

This question already has answers here:
Closed 12 years ago.
Possible Duplicate:
How can I obfuscate JavaScript?
Is there any way to protect my js file or javascript function from user to view?
You could minify/obfuscate it but the function would still be visible to the user.
Nope but you can always obfuscate. just look up online for javascript obfuscator. It makes code harder to read but it'll still be decodable.
If you need to hide code may I suggets something serverside such as php, aspx etc..
Like Darin sayd, you can obfuscate the code.
But if you want execute a js file on a browser, the user can get the source code. There is no way to avoid this.

How to call a JavaScript function in ActionScript 1?

I wold like to know how to call a JavaScript function from ActionScript 1 and get the result.
Thanks.
I haven't used AS1 for years but I used the old FSCommand in the past.
See a very detailed tutorial here:
http://www.moock.org/webdesign/flash/fscommand/
which is similar to http://forums.adobe.com/message/2701630
Another alternative here:
http://www.actionscript.org/forums/showthread.php3?t=8332
Thanks and good luck! :)

Categories

Resources