温馨提示×

javascript对象属性有哪些

养鱼的猫咪
344
2021-04-13 14:49:19
栏目: 编程语言

javascript中的对象属性有:1.constructor,返回对创建此对象的数组函数的引用;2.isPrototypeOf,检查传入对象是否是当前对象的原型;3.valueOf,返回对象的字符串、数值或布尔值表示;

javascript对象属性有哪些

javascript中的对象属性有以下几种

1.constructor属性

javascript中constructor属性的作用是用于返回对创建此对象的数组函数的引用。

constructor属性语法:

object.constructor

constructor属性使用方法:

var test=new Array();

if (test.constructor==Array)

{

document.write("This is an Array");

}

if (test.constructor==Boolean)

{

document.write("This is a Boolean");

}

输出结果为:

This is an Array

2.isPrototypeOf属性

javascript中isPrototypeOf属性的作用是用于检查传入的对象是否是当前对象的原型。

isPrototypeOf属性语法:

function.prototype.isPrototypeOf(object)

isPrototypeOf属性使用方法:

function test(){

var re = new RegExp(); //初始化变量。

return (RegExp.prototype.isPrototypeOf(re)); //返回 true。

}

3.valueOf属性

javascript中valueOf属性的作用是用于返回对象的字符串、数值或布尔值表示。

valueOf属性语法:

NumberObject.valueOf()

valueOf属性使用方法:

var str="Hello world!";

document.write(str.valueOf());

0