javascript - Whether string exists for a piece of data performs better than object
滿天的星座
滿天的星座 2017-05-24 11:32:23
0
2
815

When developing small programs or some frameworks, many request callbacks are string. Is it because string has better performance than object and json?

滿天的星座
滿天的星座

reply all(2)
曾经蜡笔没有小新

Because. . No matter what, the background response is a string. So js 在收到 object 的时候,也是一串 json 的字符串。然后,js needs to parse this string into an object. The performance is definitely better than that of an ordinary string, but the performance advantage is almost negligible. After all, if there are complex data structures, ordinary strings cannot solve the needs.

给我你的怀抱

The backend cannot be done直接Object.

The reason is very simple: there are various back-end languages, and the various Objects sent may not be treated directly as JS objects by the front-end JS.

So we need to use some kind of object representation 标准范式 to convert different types of objects into objects that JS can understand.

Perhaps you have guessed that this paradigm is JSON ———— an object representation (in string form)

In this way, any backend language can convert its object into JSON (with the help of a library or writing it yourself) and then send it to the front end, so that the front end can easily convert JSON into JS objects.

So you can see:

Different implementations of Object in multiple languages ​​=> Obejct 实现 => JSON => JavaScript => JavaScript objects

The same goes for vice versa.

Of course, there is not only JSON, a standard paradigm, but also many (xml, etc.)


Or you can think differently:

Backstage Object 调制成 JSON字符串 然后发往前端。
前端收到后 解调成 JS Object


As for the performance you mentioned, generally string operations are much faster than some operations on objects.

However, objects have hierarchical inclusion relationships and multiple data types, which string parameters do not have.

Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!