1月31

Day5
1-js 组成?
组成:
ecmascript 基本语法 变量
BOM 浏览对象模型 数据类型 Number string boolr
DOM 文档对象模型

2-js 中有哪些数据类型?
基本数据类型
number 数字类型
string 字符串类型
boolean 布尔类型
undefined 未定义
null 空

引用类型
数组 Array
对象 Object
function
3-typeof 和 instanceof 的区别
typeof:用于判断基本数据类型,返回值类型是字符串
instanceof:用于判断对象的具体类型,返回值类型是Boolean
4-怎么判断两个对象相等
function eq(a, b) {
// === 结果为 true 的区别出 +0 和 -0
if (a === b) return a !== 0 || 1 / a === 1 / b;

// typeof null 的结果为 object ,这里做判断,是为了让有 null 的情况尽早退出函数
if (a == null || b == null) return false;

// 判断 NaN
if (a !== a) return b !== b;

// 判断参数 a 类型,如果是基本类型,在这里可以直接返回 false
var type = typeof a;
if (type !== 'function' && type !== 'object' && typeof b != 'object') return false;

// 更复杂的对象使用 deepEq 函数进行深度比较
return deepEq(a, b);
};
5-js 中函数有哪些定义方式?
命名函数:
function fn1 (){
console.log("命名函数");
}
fn1();

2
var fun=function (){
console.log("命名函数");
}
fun();

匿名函数
function(){
console.log("匿名函数")
})
();


6-js 中函数有哪些调用形式?
函数形式调用
function fun(){
alert("hello world");
}
fun();

函数作为对象方法调用
var myObject = {
firstName:"John",
lastName: "Doe",
fullName: function () {
return this.firstName + " " + this.lastName;
}
}
myObject.fullName();

使用构造函数调用函数
function myFunction(arg1, arg2) {
this.firstName = arg1;
this.lastName = arg2;
}

var x = new myFunction("John","Doe");
x.firstName;


call方法
function myFunction(a, b) {
return a * b;
}
myFunction.call(myObject, 10, 2);


apply方法
function myFunction(a, b) {
return a * b;
}
myArray = [10,2];
myFunction.apply(myObject, myArray);

 

posted @ 2021-01-31 14:13  欢的大叔  阅读(57)  评论(0)    收藏  举报