微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

ES6+angular4+mysql杂记

let定义语句块变量

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);
}
//=>11111.....,无限的1,因为1恒<3
for (let i = 0; i < 3; i++) {
    let = 1;
    console.log(i);
}
//=>111,循环语句部分是一个父作用域,而循环体内部是一个单独的子作用域。

知识点:
1、类的定义
2、箭头函数为匿名函数,this指向当前类
3、类函数,this指向当前类

//使用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

知识点:
1、类的定义
2、箭头函数为匿名函数,this指向当前类
3、类函数,this指向当前类

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安装与卸载手册
MysqL-5.7.10 安装过程:

1.下载MysqL的安装文件文件URL:http://dev.mysql.com/downloads/mysql/

2.待下载*.dmg文件后双击,运行该安装文件

3.无限下一步或继续,直到 “安装”这一步。

4.MysqL-5.7版本和之前的版本不同,初始密码由系统自动生成,完成“安装”后将弹出一个提示框!!切记保留下该提示框!! ,提示框包含MysqL的初始密码。

  1. 进入MAC的偏好设置,点击MysqL服务;并启动。

6.给MysqLMysqLadmin 添加别名(壳资源文件,使其更容易命令行访问。)

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用户密码

  1. 设置环境变量。

编辑环境变量配置文件(在用户根目录下编辑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
sudo rm -rf /usr/local/MysqL*
sudo rm -rf /Library/StartupItems/MysqLCOM
sudo rm -rf /Library/PreferencePanes/My*
sudo rm -rf /Library/Receipts/MysqL*
sudo rm -rf /Library/Receipts/MysqL*
sudo rm -rf /var/db/receipts/com.MysqL.*
参考站点
设置angularcli的认包管理器

cd
到~目录
vim .angular-cli.json
{
“packageManager”: “npm”
}

踩坑记

<p [hidden]="canEdit">
    .....
</p>
//当canEdit为true时p不隐藏,查看发现p的display属性为flex,改为一下方式解决
<div [hidden]="canEdit">
    <p>
        .....
    </p>
</div>  
箭头函数:
1、减少语法
2、解决es5存在的this关键字的指向问题

for-of语句(针对数组进行的循环)

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

generator函数(可以控制函数暂停及继续执行)

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


1. 类中private申明的变量属于私有变量,供类内部方法和类构造函数调用
2. 构造函数的普通参数是不可以被类的内部方法和变量访问的
3. public关键fd字申明的参数是可以被访问的

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();

继承
子类再构造函数的参数里面要写用到的全部父类属性,在构造函数体中,使用super引用父类的这些参数

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

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

原文地址:https://www.jb51.cc/angularjs/147363.html

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。

相关推荐