//'use strict';
var username = 'kobe';
console.log(username);
function person(name,age);{
this.name = name;
this.name = age;
}
var kobe= new person('kobe,40');
var str='NBA';
// eval('alert(str)');
// eval('var str = "CBA";alert(str)');//cba
// alert(str);//nba
var obj = {
username:'kobe';//表示不能重名
username:'wade';
}
var obj = {username: 'kobe';//object {username: 'kobe'}
obj= json.stringify(obj);
console.log(typeof obj);//string {username: 'kobe'}
obj = json.parse(obj);
console.log(typeof obj);
console.log(obj.username);
}
var obj= {username: 'jordan',age:55};
var obj = {};
obj1 = Object.create(obj,{
sex:{
value:'男',
weitable:true,
configurable:true,
enumerable:true,
}
});
console.log(obj1);
console.log(obj1.sex);
obj1.sex= '女';
console.log(obj1,sex);
//delete obj1.sex;
//console.log(obj1);
for(var i in obj1){
console.log(i);
}
//
var Obj2={fiestname: 'kobe' , lastname: 'bryant'};
Object.defineProperties(Obj2,{
fullname:{
get:function(){//在获取扩展属性,
return this.firstname +"" + this.lastname;
}
set:function(data){
console.log('set()',data);
var names = data.split('');
this.fiestname = names[0];
this.fiestname = names[1];
}
}
})
console.log(obj2);
console.log(obj2,fullname);
obj2.fullname= 'tim duncan';
console.log(obj2,fullname);
var obj3 = {firstname: 'stephen',
lastname:'cueey',
get fullname(){
return this.fullname+ "" + this.lastname;
},
set fullname(data){
var names = data.split('');
this.fullname = names[0];
this.fullname = names[1];
}
};
console.log(obj3);
obj3.fullname = 'kobe bryant';
console.log(Obj3.fullname);
/*
需求:
1. 输出第一个6的下标
2. 输出最后一个6的下标
3. 输出所有元素的值和下标
4. 根据arr产生一个新数组,要求每个元素都比原来大10
5. 根据arr产生一个新数组, 返回的每个元素要大于4
*/
var arr = [2,4,3,1,2,6,5,4];
console.log(arr.indexOf(4));
console.log(arr.lastIndexOf(4));
arr.forEach(function(item, index){
console.log(item, index);
})
var arr1 = arr.map(function(item, index) {
return item + 10;
});
console.log(arr1);
var arr2 = arr.filter(function(item, index){
return item > 3;
});
console.log(arr, arr2);
var obj = {username: 'kobe'};
/*function foo(){
console.log(this);
}*/
function foo(data){
console.log(this, data);
}
// foo();
// foo.call(obj);
// foo.apply(obj);
//传入参数的形式
// foo.call(obj, 33);//直接从第二个参数开始,依次传入
// foo.apply(obj, [33]);//第二参数必须是数组,传入的参数放在数组里
//bind的特点:绑定完this不会立即调用当前的函数,而是将函数返回
/*var bar = foo.bind(obj);
console.log(bar);
bar();*/
//bind传参的方式同call一样
foo.bind(obj, 33)();
setTimeout(function(){
console.log(this);
}.bind(obj), 1000);