1.类:类于实例类似实体集与实体的关系
定义var Student = function(name, height) {
  // 用 this.变量名 来创造一个只有类的实例才能访问的变量
  this.name = name
  this.height = height
}

运用需实例化:var s1 = new Student('bai', 169)

调用 s1.name

改变属性值 s1.height = 1.9

增加属性:s1.weight = 120

可以给类增加一些方法(函数)
// 给类定义方法(想想标准库中 String 类的 length )
// prototype
Student.prototype.greeting = function() {
  console.log(`hello, I'm ${this.name}`)
}

可以调用实例的方法 s1.greeting() s1.name

一个类来说,this创建的是变量和方法,prototype创建的是方法,但是为减小内存占用,尽量this创建属性,prototype创建方法

2.this 

this:在运行时候才可以确定,只在函数内部生效,只对调用它的人生效

  最简单来说就是.前面的

  或者说除了构造函数外,其余情况下都指向了它父的父,多往上找一层

  

function test(){

    alert(this.x);

  }

  var o = {};

  o.x = 1;

  o.m = test;

  o.m(); // 1,这里父就是test(),接着父是0,


this 是一个动态作用域的东西,如何使变为静态的,用bind

var o = {
  foo: 1,
  bar: function(){
  return this.foo
  }
}

o.bar()//1 这里父就是function(),接着父是0

var a = o.bar
a()//undefined
var b = o.bar.bind(o)//1

3. apply与 call,指定执行环境,不填与填this,this是全局,填写就指定

 4.函数不改变原来数组:

  1>concat(),连接多个数组

    2>join()   3> slice()   4>tostring()

改变1>pop()   2>push()   3>reverse()   4>shift()  5>unshift()   6>sort()  7>splice()

原文地址:https://www.cnblogs.com/xiaobai1/p/8562856.html