Object Conversions

本文详细介绍了JavaScript中对象在不同上下文中如何被转换为布尔值、字符串和数值。当对象用于布尔上下文时,非空对象转换为true;在字符串上下文中,通过调用对象的toString()方法来获取其字符串表示形式;而在数值上下文中,则先尝试调用valueOf()方法获取原始值,若该方法返回对象本身,则进一步使用toString()方法将其转换为字符串,并最终将该字符串转换为数值。
[size=medium]When a non-null object is used in a Boolean context, it converts to true . When an object is used in a
string context, JavaScript calls the toString( ) method of the object and uses the string value returned
by that method. When an object is used in a numeric context, JavaScript first calls the valueOf( ) method
of the object. If this method returns a primitive value, that value is used. In most cases, however, the
valueOf( ) method returns the object itself. In this case, JavaScript first converts the object to a string
with the toString( ) method and then attempts to convert the string to a number.[/size]
上面回答的代码运行后异常提示:System.Reflection.TargetInvocationException: 调用的目标发生了异常。 ---> System.InvalidCastException: 从字符串“无法计算法线交点”到类型“Integer”的转换无效。 ---> System.FormatException: 输入字符串的格式不正确。 在 Microsoft.VisualBasic.CompilerServices.Conversions.ParseDouble(String Value, NumberFormatInfo NumberFormat) 在 Microsoft.VisualBasic.CompilerServices.Conversions.ToInteger(String Value) --- 内部异常堆栈跟踪的结尾 --- 在 Microsoft.VisualBasic.CompilerServices.Conversions.ToInteger(String Value) 在 R17._0.A4RectLayout.GetNormalIntersection(Polyline axis, Int32 index, Polyline targetLine, Transaction trans) 位置 F:\VSTO\CAD版块\R17.0\CAD多段线布矩形.vb:行号 90 在 R17._0.A4RectLayout.CalculateBoundaryPoints(Polyline axis, Polyline leftLine, Polyline rightLine, Transaction trans) 位置 F:\VSTO\CAD版块\R17.0\CAD多段线布矩形.vb:行号 65 在 R17._0.A4RectLayout.LayoutA4Rectangles() 位置 F:\VSTO\CAD版块\R17.0\CAD多段线布矩形.vb:行号 28 --- 内部异常堆栈跟踪的结尾 --- 在 System.RuntimeMethodHandle._InvokeMethodFast(Object target, Object[] arguments, SignatureStruct& sig, MethodAttributes methodAttributes, RuntimeTypeHandle typeOwner) 在 System.RuntimeMethodHandle.InvokeMethodFast(Object target, Object[] arguments, Signature sig, MethodAttributes methodAttributes, RuntimeTypeHandle typeOwner) 在 System.Reflection.RuntimeMethodInfo.Invoke(Object obj, BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture, Boolean skipVisibilityChecks) 在 System.Reflection.RuntimeMethodInfo.Invoke(Object obj, BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture) 在 AcMgCommandClass.InvokeWorker(AcMgCommandClass* , MethodInfo mi, Object commandObject, Boolean bLispFunction) 在 AcMgPerDocumentCommandClass.Invoke(AcMgPerDocumentCommandClass* , gcroot<System::Reflection::MethodInfo ^>* mi, Boolean bLispFunction) 在 Autodesk.AutoCAD.Runtime.TargetInvocationSEHExceptionFilter.InvokeWorker() 在 Autodesk.AutoCAD.Runtime.ExceptionFilter.Invoke()
最新发布
11-02
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值