赞
踩
function Person() {
var name = 'default';
this.age = 23;
Object.defineProperty(this, "name", {
get: function() {
return name;
},
set: function(newName) {
console.log(y);
name = newName;
},
enumerable: true,
configurable: true, //这两项见Javascript高级程序语言读书笔记Blog
});
}
//访问
var p = new Person();
console.log(p.name); //'default'
function subType(){
superType.call(this);
/*balabala...*/
}
subType.prototype = new superType();
subType.prototype.*** = function(){
/*balabala...*/
}
xhr = new XMLHttpRequest();
xhr.onreadystatechane = function(){
/*
if判断当xhr.readyState==4(即接收完成)时,则执行某些操作
*/
};
xhr.open('get', url, false); //最后一个参数代表是否采用同步方式执行
xhr.send(null);
function handleCallback(res) {
console.log(res);
}
var script = document.createElement('script');
script.src = 'http://freegeoip.net/json/?callback=handleCallback';
document.body.insertBefore(script, document.body.firstChild);
其中JSONP接口返回的内容如下,即作为插入到代码中执行的部分,API接口内容作为参数传入
handleCallback({
ip: "219.239.227.229",
country_code: "CN",
country_name: "China",
region_code: "11",
region_name: "Beijing",
city: "Beijing",
zip_code: "",
time_zone: "Asia/Shanghai",
latitude: 39.9289,
longitude: 116.3883,
metro_code: 0
}) //即调用了我们设置的函数handleCallback
var socket = new WebSocket('ws://api.com/api/get/id') //此处ws开头为指定的websocket协议
socket.onmessage = function(event){var data = event.data};
socket.onopen = function(){};
socket.onerror = function(){};
socket.onclose = function(){};
setTimeout(function(){
//var item = array.shift();
process(item);
if (array.length > 0){
setTimeout(arguments.callee, 100);
}
}, 100);
var processor = {
timeoutId: null,
performProcessing: function(){
//实际执行代码
},
process: function(){
clearTimeout(timeoutId);
this.timeoutId = setTimeout(() => {
this.performProcessing()
}, 100);
}
}
processor.process();
var cloneArr = arr.concat()
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。