object to primitive in javascript
例1:
var a={}; alert(a); //[object Object];
例2:
var a={
toString:function(){
return 1;
}
}
alert(a); // 1
a+1; //2
例3:
var a={toString:function(){return 1;},valueOf:function(){reuturn 2};}
alert(a); // 1
a+1; // 3
---------------------------------------------------------------------------------------------------------------------------------------------------
+操作会如下步骤:
Let lref be the result of evaluating AdditiveExpression.
Let lval be GetValue(lref).
Let rref be the result of evaluating MultiplicativeExpression.
Let rval be GetValue(rref).
Let lprim be ToPrimitive(lval).
Let rprim be ToPrimitive(rval).
Return the result of applying the addition operation to ToNumber(lprim) andToNumber(rprim). See the Note below 11.6.3.
+ specification: http://es5.github.io/index.html#x11.6.1
object to primitive in javascript的更多相关文章
- javascript中function和object的区别,以及javascript如何实现面向对象的编程思想.
<!DOCTYPE html> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <m ...
- ExtJS学习-----------Ext.Object,ExtJS对javascript中的Object的扩展
关于ExtJS对javascript中的Object的扩展.能够參考其帮助文档,文档下载地址:http://download.csdn.net/detail/z1137730824/7748893 以 ...
- bootstrap导航条报错 Uncaught TypeError: Cannot convert object to primitive value
原文: https://feiffy.cc/uncaught-typeerror-cannot-convert-object-to-primitive-value 最近发现我的博客页面移动端上下拉菜单 ...
- Unable to create a constant value of type 'System.Object'. Only primitive types or enumeration types are supported in this context.
代码如下: var query = from s in db.LoginUserServices join ss in db.Services on s.ServiceType equals ss.C ...
- JavaScript对象 Object类型基础
前言 JavaScript 对象是整个语言学习的一个难点.本文主要带大家入门学习Object知识 对象定义 javascript的基本数据类型包括undefined.null.boolean.stri ...
- 【JavaScript】Object.prototype.toString.call()进行类型判断
权声明:本文为博主原创文章,未经博主允许不得转载. op = Object.prototype, ostring = op.toString, ... function isFunction(it) ...
- JavaScript: Constructor and Object Oriented Programming
Constructor : Grammar: object.constructor Example: Javascript code: 1 function obj1() { this.number ...
- JavaScript学习总结(十一)——Object类详解
一.Object类介绍 Object类是所有JavaScript类的基类(父类),提供了一种创建自定义对象的简单方式,不再需要程序员定义构造函数. 二.Object类主要属性 1.constructo ...
- Javascript Object常用方法总结
Object.keys方法 Object.keys方法是JavaScript中用于遍历对象属性的一个方法 .它传入的参数是一个对象,返回的是一个数组,数组中包含的是该对象所有的属性名. 如: var ...
随机推荐
- GDB使用
1.display val 设置显示格式 2.i b显示所有断点
- Mac 在命令行快速切换目录 mark
转自: http://www.ccvita.com/520.html ,略修改. 每天在命令行下,一大部分的工作都是一遍又一遍的输入 cd ~/some/very/deep/often-used/di ...
- Ext js中CheckBoxGroup的动态绑定
<script type="text/jscript"> var WinXianCode; function SearchGetXianLuF(Type) { if(! ...
- view, surfaceView, invalidate, postInvalidate, 刷新屏幕
http://blog.csdn.net/linghu_java/article/details/9985489 1.view view在api中的结构 Java.lang.Object Androi ...
- Excel VBA 快捷键 代码
一. 在ThisWorkbook中 Private Sub Workbook_Open() '%对应alt键 宏不能加() Application.OnKey "%q", &quo ...
- JavaScript语言常量和变量
我们在以往介绍使用JavaScript编写一个HelloJS的小程序,其中我们就用到变量.常量和变量是构成表达式的重要组成部分.常量在声明和初始化变量时,在标识符的前面加上关键字const,就可以把该 ...
- UILabel 整理
UILabel 多行文字自动换行 (自动折行) 1.UIView *footerView = [[UIView alloc] initWithFrame:CGRectMake(10, 100, 3 ...
- 解析Path方法备忘
public static String parseDataPath(String dataPath){ StringBuilder parseBld = new StringBuilder(); L ...
- 【OSG细节实现】节点围绕位于axisPos平行于axis的轴进行旋转
//绕着与axis平行的任意轴旋转 void rotate(const std::string& name, float angle, osg::Vec3 axisPos, osg::Vec3 ...
- 探索VS中C++多态实现原理
引言 最近把<深度探索c++对象模型>读了几遍,收获甚大.明白了很多以前知其然却不知其所以然的姿势.比如构造函数与拷贝构造函数什么时候被编译器合成,虚函数.实例函数.类函数的区别等等.在此 ...