JavaScript中的对象类型是否为原始类型 [英] whether object type in JavaScript is primitive type

查看:101
本文介绍了JavaScript中的对象类型是否为原始类型的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

JavaScript中的对象类型是否为原始类型?
因为.net中的对象类型是原始类型.
JavaScript中有一个对象类,是否将对象类型包装到class(object)中?
如果是,则对象是原始类型,其中引用(例如c#)

我读到了JavaScript中所有原始类型都包装到对象的地方.
(javaScript权威指南)

whether object type in JavaScript is primitive type?
because object type in .net is a primitive type.
in JavaScript there is a object class,whether object type wrapped to in class(object)?
if yes thus object is a primitive type where are reference(Like c#)

i read where all of primitive type in JavaScript wrapped to a object.
(javaScript definitive guide book)

推荐答案

该问题在原则上是不正确的,因为JavaScript是使用松散类型(动态,弱类型,鸭子类型的学科)的解释性语言. >
请参阅 http://en.wikipedia.org/wiki/JavaScript [value = 13的内容并在Debugger下检查value.顺便说一句,所有复杂" JavaScript对象仅仅是关联数组: http://www.quirksmode.org/js/associative.html [ ^ ].

请勿将其与.NET 拳击混淆,这也不是总是"发生的事情. :-)

C#中的对象类型不是原始类型,并且C#和JavaScript方法从不相互调用.如果您有这种错觉,那可能仅仅是因为C#方法在服务器端生成了一些JavaScript代码的某些文本,参数化了生成文本以插入在服务器端计算出的相同值,但是最终所有事情都只是通过生成代码文本来完成没别的.这就是ASP.NET与JavaScript一起工作的方式.没有别的了.比较这两种语言没有意义.

—SA
The question is incorrect in principle because JavaScript is interpretive language using loose typing (dynamic, weak, duck typing discipline).

Please see http://en.wikipedia.org/wiki/JavaScript[^].

There is no a concept of a primitive type in JavaScript. More exactly, the way of interpretation of "bare" integer or Boolean values (they only exist explicitly as the result of Boolean operations) is implementation-dependent. In a way, it does not matter, because there is no such thing as a type of a variable. But "all of primitive type in JavaScript wrapped to a object" is generally not true, at least from the standpoint of JavaScript developer. You can find it out writing something like value = 13 and examining value under Debugger. By the way, all "complex" JavaScript objects are merely the associative arrays: http://www.quirksmode.org/js/associative.html[^].

Don''t mix it up with .NET boxing, which is also not something which "always" happen. :-)

Object type in C# is not a primitive type, and C# and JavaScript methods never call each other. If you have such illusion, this is maybe only because C# methods generate some text of some JavaScript code on the server side, parametrize generation of text to insert same values calculated on the server side, but ultimately everything is done just through generation of code text and nothing else. This is how ASP.NET works with JavaScript. There is nothing else. There is no point in comparison these two languages.

—SA


这篇关于JavaScript中的对象类型是否为原始类型的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆