js
放在body
元素中页面内容的后面。(1)defer
(2)async
(3)动态建立<script>标签
(4)ajax
前端
(1)增长可维护性
(2)可缓存,加快页面加载速度
(3)适应将来ajax
(1)第一个字母必须是一个字母,下划线,或者一个美圆符号
(2)其余字符能够是字母,下划线,美圆符号,或者数组json
定义:它定义了一种不一样的解析和执行模型。
做用:
(1)不肯定的行为将获得处理
(2)对某些不安全的操做会抛出错误跨域
1四、break 终止循环,continue 跳过当前循环,继续执行下个循环 ###数组
fuction person(name, age, job) { var o = new Object(); o.name = name; o.age = age; o.job = job; o.sayName = function() { alert(this.name) } return o; } var p1 = person()
function Person(name, age, job) { this.name = name; this.age = age; this.job = job; this.sayName = function() { alert(this.name) } } p1 = new Person()
和工厂方式的区别:
(1) 没有显式的建立对象;
(2)直接将属性和方法赋给你了this对象;
(3)没有reutrn 语句
建立实例的步骤:
(1)建立一个对象;
(2)讲构造函数的做用域赋给新对象;
(3)执行构造函数中的代码;
(4)返回新对象浏览器
function Person() {}; Person.prototype = { constructor: Person; nage = "bug"; age: 19; job: "coder"; sayName: function() { alert(this.name) } } var p1 = new Person()
原型模式的缺点:
(1)相同的属性值;
(2)实例被共享缓存
funcition Person(name, age, job) { this.name = name; this.age = age; this.job = job; this.friends: ['a', 'b']; } Person.prototype.sayName = function() { alert(this.name) } var p1=new Person()
function Person(name, age, job) { this.name = name; this.age = age; this.job = job; if (typeof this.sayName != "function") { Person.prototype.sayName = function() { alert(this.name) } } } var p1 = new Person()
funcition Person(name,age,job){ var o=new Object(); o.name=name; o.age=age; o.job=job; o.sayName=function(){ alert(this.name } return o; } var p1= new Person()
function Person(name, age, job) { var o = new Object(); o.sayName = function() { alert(name) } return o; } var p = Person()
function SuperType() { this.property = true; } SuperType.prototype.getSuperValue = function() { return this.property; } function subType() { this.subproperty = false; } SubType.prototype = new SuperType(); SubType.prototype.getsubValue = function() { return this.subproperty; } var instance = new subType();
function SuperType() { this.colors = ["red", "blue", "green"]; } function SubType() { SuperType.call(this) } var instance1 = new subType();
function SuperType(name) { this.name = name; this.colors = ["red", "blue", "green"]; } SuperType.prototype.sayName = function() { alert(this.name) } function SubType(name, age) { SuperTyep.call(this, name) this.age = age; } SubType.prototype = new SuperType(); SubType.prototype = construtor = SubType; subTpye.prototype.sayAge = function() { alert(this.age) } var instance1 = new SubType('bug', 30)
function object(o) { function F() {} F.prototype = o; return new F(); }
function creatAnother(original) { var clone = object(original); clone.sayHi = function() { alert("hi") } return clone; }
function SuperType(name) { this.name = name; this.colors = ["red", "blue", "green"]; } SuperType.prototype.sayName = function() { alert(this.name); } function SubType(name, age) { SuperType.call(this, name); //第二次调用SuperType() this.age = age; } SubType.prototype = new SuperType(); //第一次调用SuperType() SubType.prototype.sayAge = function() { alert(this.age); }
function fun() { var result = []; for (var i = 0; i < 10; i++) { result[i] = function() { return i; } } return reslut }
每一个函数都返回10;安全
function fun() { var reslut = []; for (var i = 0; i < 10; i++) { result[i] = function(num) { return function() { return num; } }(i) } return result; }
返回1-10服务器
(1)在全局函数中,this等于window,
(2)做为对象的方法调用时,this等于那个对象。闭包
var name = "window"; var object = { name: "object"; getName: function() { return function() { return this.name } } } alert(object.getName()()) // window var name = "window"; var object = { name: "object"; getName: function() { var _this = this; return function() { return _this.name } } } alert(object.getName()()) // object
(function(){ })()
IE: trident内核
Firefox:gecko内核
Chrome:Blink内核
一、location 对象
二、navigator 对象
三、history 对象
appendChild 添加
inserBefore 插入
replaceChild 替换
removeChild 删除
一、querySelector()
二、querySelectorAll()
三、getElementsByClassName()
4.classList 属性
(1)add()
(2)contains()
(3)remove()
(4)toggle()
五、children 属性
ajax:页面无刷新请求操做
get 用于想服务器查询信息
post 用于向服务器发送信息
跨浏览器的 CORS
function CORS(method, url) { var xhr = new XMLHttpRequest(); if ("withCredentials" in xhr) { xhr.open(method, url, true) } else if (typeof XDomainRequset != "undefined") { xhr = new XDomainRequest(); xhr.open(method, url) } else { xhr = null; } reutrn xhr; } var req = CORS("get", "wwww")
定义:动态建立script标签,回调函数