ES6+angular4+mysql杂记
var a=[];
for(let i=0;i<5;i++){ a[i]=function(){ console.log(i); }
console.log(a[i]);
};
console.log(i);
注: //第一种情况
for(var i=0;i<5;i++){
a[i]=function(){
console.log(i);
}
}
for(let j=0;j<a.length;j++){
a[j]();
}
//第二种情况
for(let i=0;i<5;i++){
a[i]=function(){
console.log(i);
}
}
for(let j=0;j<a.length;j++){
a[j]();
}
//=>12345
//第三种情况
for(var i=0;i<5;i++){
a[i]=(function(n){
console.log(n);
})(i)
}
//=>12345
//for循环中的特例
for (let i = 0; i < 3; i++) {
i = 1;
console.log(i);
}
//=>22222.....,无限的1,因为1恒<3
for (let i = 0; i < 3; i++) {
let = 1;
console.log(i);
}
//=>111,循环语句部分是一个父作用域,而循环体内部是一个单独的子作用域。
//使用bind方法绑定this
class Animal {
constructor(){
this.type = 'animal'
}
says(say){
setTimeout(function(){
console.log(this.type + ' says ' + say)
}.bind(this),1000)
}
}
//使用变量保存this指向
class Animal {
constructor(){
this.type = 'animal'
}
says(say){
var self=this;
setTimeout(function(){
console.log(self.type + ' says ' + say)
},1000)
}
}
//使用es6方法继承this
class Animal {
constructor(){
this.type = 'animal'
}
says(say){
setTimeout(()=>{ console.log(this.type + ' says ' + say) },1000) } getInfo(say){ return this.type + ' says ' + say } } var animal = new Animal() animal.says('hi') //输出都是animal says hi animal.getInfo('hi') //输出都是animal says hi
class Animal {
constructor(){}
setType(type){
(()=>{ this.type=type; })(type) } say(say){ console.log(this.type + ' says ' + say); } } var animal = new Animal() animal.setType('dog'); animal.say('汪汪汪!'); //=> dog says 汪汪汪!
animal.setType('cat');
animal.say('喵喵喵!');
//=> cat says 喵喵喵!
mac 版mysql5.7安装与卸载手册 1.下载mysql的安装文件,文件URL:http://dev.mysql.com/downloads/mysql/ 2.待下载*.dmg文件后双击,运行该安装文件 3.无限下一步或继续,直到 “安装”这一步。 4.mysql-5.7版本和之前的版本不同,初始密码由系统自动生成,完成“安装”后将弹出一个提示框!!切记保留下该提示框!! ,提示框包含mysql的初始密码。
6.给mysql、mysqladmin 添加别名(壳资源文件,使其更容易命令行访问。) alias mysql=/usr/local/mysql/bin/mysqlalias mysqladmin=/usr/local/mysql/bin/mysqladmin 7.在终端使用默认密码登陆mysql数据库(mysql 默认安装在/usr/local/mysql 下面)。 cd /usr/local/mysql/bin ./mysql -u root -p password 如果进入mysql命令行,表示安装成功。 8.修改root的默认密码 ./mysqladmin -u root -p password 你想要设置的新密码 //更改root用户密码
编辑环境变量配置文件(在用户根目录下编辑bash_profile文件,有则编辑,无则创建)。 cd ~/ vim ./bash_profile 添加内容“export PATH=/usr/local/mysql/bin:$PATH” 启用环境变量 source ./bash_profile。 二、mysql-5.7.10 卸载: 1.停止mysql服务 2.逐次执行以下命令(安装路径为默认路径) sudo rm /usr/local/mysql cd
<p [hidden]="canEdit">
.....
</p>
//当canEdit为true时p不隐藏,查看发现p的display属性为flex,改为一下方式解决
<div [hidden]="canEdit">
<p>
.....
</p>
</div>
箭头函数:
1、减少语法
2、解决es5存在的this关键字的指向问题
let a=[1,2,3,5,6];
a.desc="list";
a.forEach(value=>console.log(value));
//1、忽略数组的属性
//2、没有break方法
// 1
// 2
// 3
// 5
// 6
for(let i in a ){
console.log(a[i]);
}
//1、允许打印属性
// 1
// 2
// 3
// 5
// 6
// list
for(let i of a){
console.log(i);
}
//1、忽略数组的属性
//2、有break方法
//3、循环的是值非属性
// 1
// 2
// 3
// 5
// 6
for(let i of "lsmife"){
console.log(i);
}
// l
// s
// m
// i
// f
// e
function* trial(){
console.log('start');
yield "this is yield first";
console.log('doing');
yield "this is yield second";
console.log("finish");
}
var trys=new trial();
console.log(trys.next().value);
console.log(trys.next().value);
console.log(trys.next());
// "start"
// "this is yield first"
// "doing"
// "this is yield second"
// "finish"
// Object {
// "done": true,
// "value": undefined
// }
console.log(trys.next());
console.log(trys.next());
console.log(trys.next());
// "start"
// Object {
// "done": false,
// "value": "this is yield first"
// }
// "doing"
// Object {
// "done": false,
// "value": "this is yield second"
// }
// "finish"
// Object {
// "done": true,
// "value": undefined
// }
function ShowMe(name) {
this.name = name;
setTimeout(function () {
console.log("name is" + this.name);
},1000)
}
var a = new ShowMe('lsmife');
//name is
function ShowMeEs6(name) {
this.name = name;
setTimeout(()=>{
console.log("name is " + this.name);
},1000)
}
var b = new ShowMeEs6('lsmife');
//name is lsmife
class Person{ constructor(public name:string) { } eat() { alert(`this is : ${this.name}`); } } let p1 = new Person('lsmife'); p1.eat(); //this is : lsmife class Person{ constructor(public name:string) { } eat() { alert(`this is : ${this.name}`); } } let p1 = new Person('lsmife'); p1.eat(); //this is : lsmife class Person{ name; constructor(name: string) { this.name = name; } eat() { alert(`this is : ${this.name}`); } } let p1 = new Person('lsmife'); p1.eat(); //this is : lsmife class Person{ private name; constructor(name: string) { this.name = name; } eat() { alert(`this is : ${this.name}`); } } let p1 = new Person('lsmife'); p1.eat();
class Person{
constructor(public pname:string,public age:number,public gender:string) {
}
getInfo() {
console.log(`I am ${this.pname} I am ${this.age}'s old I am ${this.converGender(this.gender)} `)
}
converGender(gen: string) {
let gender: string="男";
switch (gen) {
case 'm':
gender= "男";
break;
case 'w':
gender= '女';
break;
}
return gender;
}
}
class Employee extends Person{
constructor(public pname:string,public gender:string,public nos: string,public company: string,public addr: string) {
super(pname,age,gender);
}
getEinfo() {
super.getInfo();
console.log(`my no is : ${this.nos} my company is : ${this.company} my company's addr is : ${this.addr}`)
}
}
let e1 = new Employee('lsmife',21,'m','0708300054','众荟信息股份有限公司','北京市海淀区金澳国际大厦')
e1.getEinfo()
//I am lsmife
//I am 21's old
//I am 男
//my no is : 0708300054
//my company is : 众荟信息股份有限公司
//my company's addr is : 北京市海淀区金澳国际大厦
interface Person{
names: string;
age: number;
}
class Empolee{
pers: any;
constructor(p: Person) {
this.pers=p
}
getInfo() {
console.log(`my name is ${this.pers.names}
my age is ${this.pers.age}`)
}
}
let persons: Person = {
names: 'lsmife',age:12
}
let ens = new Empolee(persons);
ens.getInfo()
//my name is lsmife
//my age is 12 (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |