Get exact syntax of javascript base functions [duplicate] - javascript

This question already has answers here:
Where can I find javascript native functions source code? [duplicate]
(3 answers)
Javascript native sort method code
(3 answers)
Closed 8 years ago.
Is there a way to know how test (for regex) or cos (for math) or substring (for string) or splice (for array) have been coded in the exact syntax either by a way in Javascript (like alert(function)) or by seeking in the files that come with Firefox?

Well, the source code of javascript likely isn't written in javascript itself, so you would be unable to just print it to the browser console or alert.
You can browse the source code of google's V8 engine, and see if it helps you ;)
http://code.google.com/p/v8/

These functions are actually implemented differently by browsers in one of the OS native languages.
So these algorithms are written in c, c++, c#, java etc. but not in JavaScript.

Related

Can you override what == does in Javascript? [duplicate]

This question already has answers here:
Override the Equivalence Comparison in Javascript
(5 answers)
Overloading Arithmetic Operators in JavaScript?
(11 answers)
Closed 6 years ago.
In Python, it's possible to override what == does by defining a __eq__ method for your class.
Is it possible to do something similar in Javascript? If so, how do you do it?
My understanding is that, by default (and maybe always, if you can't override it), Javascript just checks to see if two objects reside at the same address when you do a ==. How can I get the address directly?
I'm asking all of this because I'm trying to debug some code someone who's long gone wrote. As far as I can tell, two objects are identical, and yet == is returning false. I'm trying to find why... I'm wondering if maybe == was overridden someplace (but it's a big codebase and I don't know what to search for) or if or if maybe the object was duplicated, so they exist at different addresses despite being identical as far as I can tell. Knowing how to get the address would help with confirming that theory and give me a lead to hunt down the problem.
Not typically. JS does not allow operator overloading or operators-as-methods.
There are certain operators that call toString or valueOf internally, which you can override on your own classes, thus influencing the behavior.
No, it is not possible to override any operators directly in JavaScript.

Does JavaScript support a ByteArray class in the browser? [duplicate]

This question already has answers here:
How to store a byte array in Javascript
(4 answers)
Closed 7 years ago.
The ByteArray class provides methods and properties to optimize reading, writing, and working with binary data.
How to use byte arrays tutorial.
I'm looking for a very similar API as the one linked.
I'm looking for a class the browser provides not hack or workaround. The linked question does not provide the answer. If it does please provide a link to the documentation.
Some one linked to another question but that did not answer my question.
Update: Someone off list pointed me to this class:
https://gist.github.com/sunetos/275610#file-bytearray-js
It has most or all of the read methods but none of the write methods and it's not native to the browser.
Modern browsers support Uint8Array, one of JavaScript's TypedArray classes.
var data = new Uint8Array(8);
var data = new Uint8Array([0x10, 0x12]);
It does not have built-in methods for encoding/decoding Unicode strings. See Converting between strings and ArrayBuffers for examples of how to do that.
The answer is yes, here are the relevant docs since you just wanted this...
https://developer.mozilla.org/en-US/docs/Web/JavaScript/Typed_arrays
The linked docs for each type in the above docs show the methods available on each type. IE: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Int8Array

Encrypt javascript file [duplicate]

This question already has answers here:
How can I hide or encrypt JavaScript code? [duplicate]
(7 answers)
Closed 4 years ago.
I don't find any info about that,so asking here.
Is somebody ever used some tool to protect javascript files? And totaly encrypt them?
Because I found this tool that seems like can totaly encrypt JS?
What do you think?
http://webtools.securitygeeks.net/p/blog-page_26.html?
That tool is useless. It declares a global variable called teksasli which contains your original script in a plain string. just look at the value of that variable in any console to see the original source.
There is no point in trying to encrypt Javascript, because the user/browser needs to decrypt it in order to run it.
If you want to obfuscate the source code, You could try GWT http://mojo.codehaus.org/gwt-maven-plugin/ (The Google Web Toolkit ).

Javascript Processing in browser [duplicate]

This question already has answers here:
Closed 10 years ago.
Possible Duplicate:
How does a JavaScript parser work?
How do browsers compile Javascript scripts? What type of compiler it used?
JavaScript isn't compiled, but rather parsed and interpreted. This differs from browser to browser.
Chrome, uses V8, which happens to also be used by node.js. Internet Explorer has a proprietary engine known as Chakra.
As for general rules, the Annotated ES5 shares some insight:
The source text of an ECMAScript program is first converted into a sequence of input elements, which are tokens, line terminators, comments, or white space. The source text is scanned from left to right, repeatedly taking the longest possible sequence of characters as the next input element.
The browsers don't compile javascript, it just parse the file and execute it.
Look here: JavaScript_engine
Javascript gets interpreted; this is like compiled on the fly, while running, when needed. That's why a page with javascript errors will just work until a part of bad code gets used. the bad code block will just stop.

Howto convert E4X XML Elements into JSON Notation [duplicate]

This question already has answers here:
Convert XML to JSON (and back) using Javascript
(14 answers)
Closed 8 years ago.
I have a server Implementation of ECMA Script including the ability to use E4X. Because this is pretty elegant for people don't know JavaScript and JSON Notation and we want to make an API which is most easy to learn i want to use this for my API.
I'm currently evaluating if i can use this in my environment. One Showstopping feature that i must use is to convert those XML Objects of E4X into JSON compatible JavaScript Objects or Strings on the fly. I can't use XSLT here because i have to stay inside JavaScript.
So the question is, is there an easy way to convert E4X XML Elements into JSON? Or do i have to write some code to convert it myself?
You can use XSLT to convert your XML to JSON.
For instance using: http://code.google.com/p/xml2json-xslt/
However you can end up with a very XMLish and unnecessarily complex JSON. That will make your code more difficult to write and maintain.
An API is generally meant to be stable in time, so may be some dedicated XSLT for each calls may be a better option than a generic one.

Categories

Resources