js constructor不修正药业美添白副作用没多大副作用

相关内容AD728-250大家还关注AD728-250JavaScript constructor 属性详解
对象的constructor属性用于返回创建该对象的函数,也就是我们常说的构造函数。在JavaScript中,每个具有原型的对象都会自动获得constructor属性。除了arguments、Enumerator、Error、Global、Math、RegExp、Regular Expression等一些特殊对象之外,其他所有的JavaScript内置对象都具备constructor属性。例如:Array、Boolean、Date、Function、Number、Object、String等。所有主流浏览器均支持该属性。语法object.constructor返回值对象的constructor属性返回创建该对象的函数的引用。示例&说明以下代码中的[native code],表示这是JavaScript的底层内部代码实现,无法显示代码细节。// 字符串:String()
var str = &张三&;
document.writeln(str.constructor); // function String() { [native code] }
document.writeln(str.constructor === String); // true
// 数组:Array()
var arr = [1, 2, 3];
document.writeln(arr.constructor); // function Array() { [native code] }
document.writeln(arr.constructor === Array); // true
// 数字:Number()
var num = 5;
document.writeln(num.constructor); // function Number() { [native code] }
document.writeln(num.constructor === Number); // true
// 自定义对象:Person()
function Person(){
this.name = &CodePlayer&;
var p = new Person();
document.writeln(p.constructor); // function Person(){ this.name = &CodePlayer&; }
document.writeln(p.constructor === Person); // true
// JSON对象:Object()
var o = { &name& : &张三&};
document.writeln(o.constructor); // function Object() { [native code] }
document.writeln(o.constructor === Object); // true
// 自定义函数:Function()
function foo(){
alert(&CodePlayer&);
document.writeln(foo.constructor); // function Function() { [native code] }
document.writeln(foo.constructor === Function); // true
// 函数的原型:bar()
function bar(){
alert(&CodePlayer&);
document.writeln(bar.prototype.constructor); // function bar(){ alert(&CodePlayer&); }
document.writeln(bar.prototype.constructor === bar); // true
我们认为:
用户的主要目的,是为了获取有用的信息,而不是来点击广告的。因此本站将竭力做好内容,并将广告和内容进行分离,确保所有广告不会影响到用户的正常阅读体验。用户仅凭个人意愿和兴趣爱好点击广告。
我们坚信:只有给用户带来价值,用户才会给我们以回报。
CodePlayer技术交流群1:
帮朋友打一个硬广告:
P2P网贷系统(Java版本) 新年低价大促销,多年P2P技术积累,系统功能完善(可支持资金存管),架构稳定灵活、性能优异、二次开发快速简单。
另可提供二次开发、安装部署、售后维护、安全培训等一条龙服务。
外行看热闹,内行看门道。可以自信地认为,在系统设计上,比市面上的晓风、迪蒙、方维、绿麻雀、国融信、金和盛等P2P系统要好。
深圳地区支持自带技术人员现场考察源代码、了解主要技术架构,货比三家,再决定是否购买。
也可推荐他人购买,一旦完全成交,推荐人可获得实际售价 20% 的返现。
有意向者,详情请
联系,工作时间立即回复。
打开导航菜单2498人阅读
javaScript(18)
Javascript确实是很烦人, 但也很诱人
这次记录constructor, 与之相关的, 还有typeof, ==, ===
试测测以下代码的结果
function demo(){
var str1=&abc&;
var str2=new String(&abc&);
var str3=new Array(&abc&);
alert(typeof str1);
alert(typeof str2);
alert(typeof str3);
alert(str1.constructor);
alert(str2.constructor);
alert(str3.constructor);
alert(str1 instanceof String);
alert(str2 instanceof String);
alert(str3 instanceof Array);
alert(str1==str2);
alert(str1==str3);
alert(str2==str3);
alert(str1===str2);
alert(str1===str3);
alert(str2===str3);
function String(){...}
function String(){...}
function Array(){...}
false& //*1, string比较麻烦
false //*2, 2个实例进行==运算, 肯定false, 哪怕重写prototype valueOf()和toString()
*1, string在JS里很麻烦, 介于基本类型和对象之间, typeof &abc& -& string
&abc&.constructor也是function String(){...}
但, &abc& instanceof String 却又是false, 在没有进一步了解之前, 权当是历史遗留问题吧
*2, ==运行, 对象跟string(非String)时, 会先调用对象的valueOf取值, 如果没有valueOf, 则调用toString, 然后跟string对比, 但Date对象是先toString, 然后才是valueOf
function demo(){& &&& var A=function(n){& &&&&&&& this.name=n;& &&& }& &&& A.prototype.valueOf=function(){return
this.}& A.prototype.toString=function(){return
&A: &+this.}&
&&& var B=function(n){& &&&&&&& this.name=n;& &&& }& &&& B.prototype.valueOf=function(){return
this.}& &&& B.prototype.toString=function(){return
&B: &+this.}&
&&& var c=&david&;& &&& var a=new A(&david&);&
&&& var b=new B(c);& &&& alert(c==a);& &&& alert(c==b);& &&& alert(a==b);& }&
看见上面的结果了吧, 有够烦人的
下面还有, 但好理解一点, 关于继承的
function demo(){& &&& var A=function(name){& &&&&&&& this.name=& &&& }& &&& A.prototype.showName=function(){alert(this.name);}
&&& A.prototype.showSex=function(){alert(&male&);}&
&&& A.prototype.city=&shenzhen&;&
& &&& var B=function(name, age){& &&&&&&& A.call(this, name);&
&&&&&&& this.age=& &&& }& &&& B.prototype=A.& &&& B.prototype.showAge=function(){alert(this.age);}&
& &&& var b=new B(&david&,
31);& &&&&& &&& try {& &&&&&&& alert(b.constructor);&&&&&& &
&&&&&&& alert(b.constructor==A);&&& &
&&&&&&& alert(b.constructor==B);&&& &
&&&&&&& alert(b instanceof A);&&&&&
& &&&&&&& alert(b instanceof B);&&&&&
& &&& } catch (exception) {& &&&&&&& alert(exception);& &&& }& }&
1:function A{this.name=}
3:false //构造器指针指向A
参考知识库
* 以上用户言论只代表其个人观点,不代表CSDN网站的观点或立场
访问:1891955次
积分:18572
积分:18572
排名:第370名
原创:279篇
转载:204篇
评论:404条
(7)(1)(1)(2)(11)(5)(3)(6)(10)(7)(1)(8)(7)(4)(2)(2)(6)(3)(10)(7)(4)(5)(6)(4)(6)(6)(8)(8)(10)(4)(2)(11)(2)(21)(2)(8)(9)(9)(13)(6)(3)(4)(9)(6)(5)(2)(7)(1)(1)(1)(4)(1)(1)(1)(11)(5)(12)(6)(3)(1)(7)(4)(1)(1)(2)(2)(7)(7)(4)(2)(1)(3)(1)(2)(20)(32)(19)(13)(11)(5)(11)(8)}

我要回帖

更多关于 修正蛇鞭粉副作用吗 的文章

更多推荐

版权声明:文章内容来源于网络,版权归原作者所有,如有侵权请点击这里与我们联系,我们将及时删除。

点击添加站长微信