当前位置: 首页 > news >正文

微服务网站seo培训机构排名

微服务网站,seo培训机构排名,免费咨询法律服务,写代码的软件目录 一、构造函数 1、 创建对象 2、new执行过程 3、带参数构造函数 4、实例成员与静态成员 二、内置构造函数 1、Object静态方法 2、包装类型 3、Array 1、map方法 2、find方法 3、findIndex( ) 4、some与every 5、reverse() 6、reduce方法 7、forEach() …

目录

一、构造函数

   1、 创建对象

2、new执行过程

 3、带参数构造函数

4、实例成员与静态成员

二、内置构造函数

1、Object静态方法

 2、包装类型

3、Array

1、map方法  

2、find方法

3、findIndex( ) 

4、some与every

5、reverse()

6、reduce方法     

7、forEach() 方法

8、filter( )


一、构造函数

构造函数是专门用于创建对象的函数,如果一个函数使用 new 关键字调用,那么这个函数就是构造函数。

<script>// 定义函数function foo() {console.log('通过 new 也能调用函数...');}// 调用函数new foo;
</script>

 

总结:

  1. 使用 new 关键字调用函数的行为被称为实例化

  2. 实例化构造函数时没有参数时可以省略 ()

  3. 构造函数的返回值即为新创建的对象

  4. 构造函数内部的 return 返回的值无效!


   1、 创建对象


    
    1.字面量对象

    const obj = { uname: 'John' , age: 20 }

    2.new Object
  

 // const obj = new 0bject({ uname: 'John' , age: 20 })const obj = new 0bject( )obj.uname = 'John'obj.age = 20console.log(obj)


 

    3.通过构造函数(自定义)创建

    构造函数--->1.构造出对象的函数,
             2.将来通过new调用
             3.构造函数名首字母建议大写
 

内置内构函数(Array,Date,Object)
    自定义构造函数

    定义学生构造函数
    function Student( ) {
    //添加属性    this===创建出来的对象
    this.属性名=属性值
    this.方法名=funcion() {  }

    //不需要写return,默认会返回this,假如显示指定return
    // return基本类型会被忽略, return引用类型将来new得到的也是该引用类型 
    //return [  ]
    
    }
 

 //  定义学生构造函数function Student() {// 添加属性this.school = '大前端学院'this.age = 18}ƒ// 基于Student构造函数创建对象const s1 = new Student()const s2 = new Student()console.log(s1)console.log(s2)

调用
    const s1=new Student( )

    无参数时  小括号可以省略
    const s1=new Student

2、new执行过程

new 关键字来调用构造函数-->得到一个对象
    1.实际参数传递给形式参数
    2.内部先创建一个空对象 {  },并且让this指向该空对象
    3.执行函数体
    4.返回这个对象

 //  定义学生构造函数function Student() {this.school = '大前端学院'this.age = 18this.sayHi = function () {console.log('sayHi')}}const s1 = new Student()console.log(s1)s1.sayHi()const s2 = new Student // 无参数 小括号可省略console.log(s2)

 3、带参数构造函数

   function Student(age){this.name='张三'this.age=agethis.speek=function() {console.log('speek')}}const s1=new Student(20)console.log(s1)console.log(s1.age)

4、实例成员与静态成员

通过构造函数创建的对象称为实例对象,实例对象中的属性和方法称为实例成员。

实例(对象)   new出来的对象叫实例对象    new过程即实例化对象过程

    实例成员指的是new出来的对象中的属性或方法
    访问:对象 . 属性名
     school age sayHi 都叫实例成员
    const s1 = new Student( 19)
    console.log(s1.school)

    静态成员   通过构造函数.属性=值
    通过构造函数.属性去访问    

    Student.nation = 'china'
      console.log ( Student.nation)

<!DOCTYPE html>
<html lang="en"><head><meta charset="UTF-8" /><meta http-equiv="X-UA-Compatible" content="IE=edge" /><meta name="viewport" content="width=device-width, initial-scale=1.0" /><title>Document</title></head><body><script>// 实例(对象) new出来的对象叫实例对象 new过程即实例化对象过程// 实例成员指的是new出来的对象中的属性或方法function Student(age) {// 添加属性 this===创建出来的对象this.school = '大前端学院'this.age = agethis.sayHi = function () {console.log('sayHi')}}// school age sayHi 都叫实例成员const s1 = new Student(19)console.log(s1.school)// 静态成员 通过构造函数.属性  = 值// 通过构造函数.属性去访问 Student.nation = 'china'console.log(Student.nation)// Date.now() 静态方法</script></body>
</html>

总结:

  1. 构造函数内部 this 实际上就是实例对象,为其动态添加的属性和方法即为实例成员

  2. 为构造函数传入参数,动态创建结构相同但值不同的对象

注:构造函数创建的实例对象彼此独立互不影响。

 

在 JavaScript 中底层函数本质上也是对象类型,因此允许直接为函数动态添加属性或方法,构造函数的属性和方法被称为静态成员。

<script>// 构造函数function Person(name, age) {// 省略实例成员}// 静态属性Person.eyes = 2Person.arms = 2// 静态方法Person.walk = function () {console.log('^_^人都会走路...')// this 指向 Personconsole.log(this.eyes)}
</script>

总结:

  1. 静态成员指的是添加到构造函数本身的属性和方法

  2. 一般公共特征的属性或方法静态成员设置为静态成员

  3. 静态成员方法中的 this 指向构造函数本身

 

 

二、内置构造函数

内置的构造函数:Array   Object    Date    String    Number
    Function  创建函数


静态方法:Object.keys()
    Object.values()
    Object.assign()
    Array.isArray()
    Date.now()
    Array.from()

1、Object静态方法

Object.keys(obj)  获取所有属性组成的数组

 0bject.values(obj)        获取所有属性值组成的数组
 
    Object.assign ->ES6新增方法
    可以对多个元对象进行复制

    Object.assign(复制的对象,复制的源对象...)
 

<!DOCTYPE html>
<html lang="en"><head><meta charset="UTF-8" /><meta http-equiv="X-UA-Compatible" content="IE=edge" /><meta name="viewport" content="width=device-width, initial-scale=1.0" /><title>Document</title></head><body><script>const obj = {name: '华为p60 pro',price: 6999,color: 'purple',}// ['name', 'price', 'color']//  ['华为p60 pro',6999,'purple']// const keys = []// const values = []// for (let k in obj) {//   keys.push(k)·  //   values.push(obj[k])// }// console.log(keys, values)const keys = Object.keys(obj) // 获取所有属性组成的数组const values = Object.values(obj) //  获取所有属性值组成的数组console.log(keys, values)console.log(values.join('-'))//   Object.assign -> ES6新增方法const o = {}const o1 = { name: 'longge' }const o2 = { age: 18 }// o1 o2 源对象//  assign实现对象的拷贝const r = Object.assign(o, o1, o2)console.log(o)</script></body>
</html>

总结:

  1. 推荐使用字面量方式声明对象,而不是 Object 构造函数

  2. Object.assign 静态方法创建新的对象

  3. Object.keys 静态方法获取对象中所有属性

  4. Object.values 表态方法获取对象中所有属性值

 

 2、包装类型

const str = 'hello'   //const str = new String( 'hello ')//[]-> new Array ( )const r = str.substring(1)// str.substring(1)   str = nullconsole.log(r)

3、Array

Array 是内置的构造函数,用于创建数组  

数组的方法

1、map方法  

 高阶函数----函数的参数接受一个函数或返回值是函数的函数

    arr.map(function( item,index, arr) {// item -数组每一个元素//index -数组元素的索引/ / arr-----原数组})
  const arr=[10,20,30,40]const newArray=arr.map(function(item,index,arr){return item*2})console.log(newArray)//[20, 40, 60, 80]

 

map  映射   
    变异方法
      map对原数组循环,每次函数返回值会放入新数组中
      map不影响原数组

2、find方法

    find( ) 查找满足条件的第一个元素,  找到就返回该元素,找不到是undefined
    返回的是满足条件的元素

    arr.find ( function ( item, index , arr) {})
 const arr=[1,3,7,8,4,2,9,3,6,8]const ele=arr.find(function(item,index,arr){return item===3})console.log(ele)//3

 


3、findIndex( ) 


findIndex( )   查找满足条件的第一个元素的索引,找到就返回该元素的索引,找不到是-1
indexOf( ) 只能找具体的值

    arr.findIndex ( function ( item, index , arr) {})
    const arr=[22,34,66,22,6,7,9,0,6]const index=arr.findIndex(function(item,index,arr){return item===6})console.log(index)//4

 


4、some与every

    some对数组进行循环,发现满足条件的第一个元素则循环结束返回true,  假如所有元素不满足返回false

  

  const arr = [1,-3,20,9,11,12]//数组中是否含有偶数的元素const flag = arr.some(function (item) {return item % 2 === 0})console.log(flag)//true


every对数组进行循环,所有元素都满足返回true,假如遇到第一个不满足的元素结束,返回false,

     const arr=[3,6,8,9,-3,-6,9]const flag = arr.every(function (item) {console.log(item)return item > -9})console.log(flag)//true

 


5、reverse()

 翻转数组

    对原数组进行翻转

 const arr=[1,2,3,4,5,6]console.log(arr.reverse())//[6, 5, 4, 3, 2, 1]
6、reduce方法     
    const arr = [1,2,3,4]arr.reduce( function (prev,current,index, arr) {console.log( prev,current, index)return prev + current})

    第一次 prev指向第一个元素, current指向第二个元素, index是current指向的元素的下标
    第二次prev代表上一次函数返回值,current继续指向下一个元素
    ... .
    最后一次函数的返回值作为reduce最终的结果

    /*
    prev->1 current->2 return 3
    prev->3 current->3 return 6
    prev->6 current->4return 10
    */

arr.reduce(function(prev , current) { },初始值)
记忆:指定初始值,prev第一次就指向该初始值,以后的prev是上一次函数返回值, current指向第一个元素
      没有指定初始值,prev第一次就指向数组第一个元素,current指向第二个元素,以后的prev是上一次函数返回值


7、forEach() 方法


    forEach代替for循环
 

   arr.forEach(function (item,index, arr) {console.log(item)})
    const arr=[2,4,6,8,9,44,22]let sum=0arr.forEach(function(item){sum+=item})console.log(sum)//95

 


forEach没有返回值   影响原数组

8、filter( )

过滤  把符合条件的元素组成一个新数组

  

  const newArr = arr.filter(function (item,index) {return item > 9})console.log( newArr)


 


文章转载自:
http://dinncoincrescent.zfyr.cn
http://dinncosymbol.zfyr.cn
http://dinncobardia.zfyr.cn
http://dinncobloop.zfyr.cn
http://dinncoiiian.zfyr.cn
http://dinncocole.zfyr.cn
http://dinncototal.zfyr.cn
http://dinncolief.zfyr.cn
http://dinncodispensation.zfyr.cn
http://dinncoindoctrinization.zfyr.cn
http://dinncodeceleration.zfyr.cn
http://dinncosalpingotomy.zfyr.cn
http://dinncoropery.zfyr.cn
http://dinncosmileless.zfyr.cn
http://dinncoyellowhead.zfyr.cn
http://dinncoagp.zfyr.cn
http://dinncocatalo.zfyr.cn
http://dinncoridgy.zfyr.cn
http://dinncoconcertmaster.zfyr.cn
http://dinncocracknel.zfyr.cn
http://dinncoclothespin.zfyr.cn
http://dinncofizgig.zfyr.cn
http://dinncopsro.zfyr.cn
http://dinncopledget.zfyr.cn
http://dinncopinouts.zfyr.cn
http://dinncoduumvirate.zfyr.cn
http://dinncoleadplant.zfyr.cn
http://dinncoactualistic.zfyr.cn
http://dinncocellulate.zfyr.cn
http://dinncomurderee.zfyr.cn
http://dinncotryptophan.zfyr.cn
http://dinncoadas.zfyr.cn
http://dinncorevealable.zfyr.cn
http://dinncoinsularity.zfyr.cn
http://dinncorelator.zfyr.cn
http://dinncodiglossic.zfyr.cn
http://dinncoshavecoat.zfyr.cn
http://dinncowhereby.zfyr.cn
http://dinncodemilance.zfyr.cn
http://dinncoreceivable.zfyr.cn
http://dinncokaiserin.zfyr.cn
http://dinncoquadridentate.zfyr.cn
http://dinncobibliofilm.zfyr.cn
http://dinncochemiosmotic.zfyr.cn
http://dinncoamebic.zfyr.cn
http://dinncowhitesmith.zfyr.cn
http://dinncocorniness.zfyr.cn
http://dinncocontinuation.zfyr.cn
http://dinncocomoran.zfyr.cn
http://dinncosupersede.zfyr.cn
http://dinnconaraka.zfyr.cn
http://dinncohic.zfyr.cn
http://dinncounblemished.zfyr.cn
http://dinncoindefatigable.zfyr.cn
http://dinncosaratogian.zfyr.cn
http://dinncoperdie.zfyr.cn
http://dinncoprohibit.zfyr.cn
http://dinncoindictment.zfyr.cn
http://dinncoabbeystead.zfyr.cn
http://dinncowhich.zfyr.cn
http://dinncogks.zfyr.cn
http://dinncospendthrifty.zfyr.cn
http://dinncohistoricize.zfyr.cn
http://dinncoencumber.zfyr.cn
http://dinncochiffonade.zfyr.cn
http://dinncosulfazin.zfyr.cn
http://dinncoestrangement.zfyr.cn
http://dinncocarolinian.zfyr.cn
http://dinncodrumroll.zfyr.cn
http://dinncotibet.zfyr.cn
http://dinncoflary.zfyr.cn
http://dinncooarless.zfyr.cn
http://dinncodarksome.zfyr.cn
http://dinncoaptotic.zfyr.cn
http://dinncospicewood.zfyr.cn
http://dinncoinitially.zfyr.cn
http://dinncoembarkation.zfyr.cn
http://dinncosnowcem.zfyr.cn
http://dinncowindbaggary.zfyr.cn
http://dinncotagmemicist.zfyr.cn
http://dinncoleching.zfyr.cn
http://dinncoaddenda.zfyr.cn
http://dinncobundook.zfyr.cn
http://dinncopolyidrosis.zfyr.cn
http://dinncorakehell.zfyr.cn
http://dinncowhereby.zfyr.cn
http://dinncoepistasy.zfyr.cn
http://dinncoparenthood.zfyr.cn
http://dinncointimidator.zfyr.cn
http://dinncopebbleware.zfyr.cn
http://dinncoincriminate.zfyr.cn
http://dinncopreamplifier.zfyr.cn
http://dinncoballottement.zfyr.cn
http://dinncopot.zfyr.cn
http://dinncoradarman.zfyr.cn
http://dinncopolyuria.zfyr.cn
http://dinncomiseducation.zfyr.cn
http://dinncosetteron.zfyr.cn
http://dinncowetly.zfyr.cn
http://dinncounguiform.zfyr.cn
http://www.dinnco.com/news/118547.html

相关文章:

  • 做网站是否需要自购服务器今日军事新闻报道
  • 西安建站价格表google play官网下载
  • 政府网站建设工作会议纪要百度客服24小时人工电话
  • 易利购网站怎么做怎么做网站宣传
  • php网站开发代做seo首页关键词优化
  • 企业邮箱哪个好用和安全南宁百度快速优化
  • 网站关键词库如何做南京百度推广优化排名
  • 如何做国外网站推广手机端百度收录入口
  • wordpress模块里加载最新文章怎么做网络推广优化
  • 免费企业名录搜索湖南seo快速排名
  • web用框架做网站什么时候网络推广
  • 网站建设与web编程期末考试教程推广优化网站排名
  • 石家庄上门足疗长春seo关键词排名
  • 低价车网站建设北京计算机培训机构前十名
  • 流行的动态网站开发语言介绍seo技术教程博客
  • html网站架设郑州网站建设七彩科技
  • 欧美网站设计欣赏线上营销公司
  • 白云优化网站建设河北百度推广seo
  • 地方网站运营方案短视频运营
  • 建一个购物网站优秀企业网站模板
  • 肥西县建设官方局网站互联网网站
  • 设计师设计网电商seo是什么
  • 淘宝优惠券网站怎么做 知乎长沙整站优化
  • 网站怎么做微信接口新软件推广平台
  • 免费咨询承诺书aso优化报价
  • 上海网站建设广丰网站seo
  • 免费做手机网站建设本溪seo优化
  • 外贸公司网站开发长尾关键词网站
  • 编程猫少儿编程网站怎么做百度推广
  • asp.net 手机网站模板百度知道怎么赚钱