版权声明:本文为博主原创文章,若文章中有错误请联系博主改正,请不要恶意留言(不喜欢请绕道)。欢迎大家转载,转载时请注明原文地址:https://blog.csdn.net/qq_37674616/article/details/82177270
目录
Function类型
1.函数的创建
-
函数的声明
function sayHello(){
console.log("hello");
}
-
函数表达式
var say=function(){
console.log("hello");
}
2.函数属性和方法
ECMAScript中函数就是对象,因此函数也有属性和方法。
-
继承属性
1.length
length属性表示函数希望接纳的命名参数个数
2.prototype
function sayName(name){
console.log(name);
}
function sum(num1,num2){
return num1+num2;
}
function sayHi(){
console.log("hi");
}
conosle.log(sayName.length) //1
conosle.log(sum.length) //2
console.log(sayHi.length) //0
-
非继承的方法
apply()和call()真正用途是扩充函数赖以运行的作用域
1. apply()
该方法接受两个参数:一个是在其中运行 函数的作用域,另一个是参数数组。其中参数数组可以是数值或arguments对象(类数组对象)
function Person(name,age){
this.name=name;
this.age=age;
}