当前位置: 首页 > news >正文

武汉公司建站广告软文范例

武汉公司建站,广告软文范例,接入备案和增加网站,wordpress开始https乱文章目录 一、类1.1 基本示例1.2 继承1.3 实例成员访问修饰符1.3.1 public 开放的1.3.2 private 私有的1.3.3 protected 受保护的1.3.4 readonly 只读的1.3.5 在参数中使用修饰符 1.4 属性的存(get)取(set)器1.5 静态成员 二、函数…

文章目录

    • 一、类
      • 1.1 基本示例
      • 1.2 继承
      • 1.3 实例成员访问修饰符
        • 1.3.1 `public` 开放的
        • 1.3.2 `private` 私有的
        • 1.3.3 `protected` 受保护的
        • 1.3.4 `readonly` 只读的
        • 1.3.5 在参数中使用修饰符
      • 1.4 属性的存(get)取(set)器
      • 1.5 静态成员
    • 二、函数
      • 2.1 函数参数
      • 2.2 箭头函数
    • 三、for-of 循环
    • 四、类型推断(Type Inference)
    • 五、模块
      • 5.1 概念
      • 5.2 模块通信:导出
      • 5.3 模块通信:导入

一、类

1.1 基本示例

class Person {name: string;age: number;constructor(name: string, age: number) {this.name = name;this.age = age;}sayHello() {console.log(this.name);}
}let zs: Person = new Person('张三', 18);

1.2 继承

class Animal {move(distanceInMeters: number = 0) {console.log(`Animal moved ${distanceInMeters}m.`);}
}class Dog extends Animal {bark() {console.log('Woof! Woof!');}
}const dog = new Dog();
dog.bark();
dog.move(10);
dog.bark();

这个例子展示了最基本的继承:类从基类中继承了属性和方法。 这里, Dog是一个 派生类,它派生自 Animal 基类,通过 extends关键字。 派生类通常被称作 子类,基类通常被称作 超类

因为 Dog继承了 Animal的功能,因此我们可以创建一个 Dog的实例,它能够 bark()move()

下面是一个更复杂的例子:

class Animal {name: string;constructor(theName: string) { this.name = theName; }move(distanceInMeters: number = 0) {console.log(`${this.name} moved ${distanceInMeters}m.`);}
}class Snake extends Animal {constructor(name: string) { super(name); }move(distanceInMeters = 5) {console.log("Slithering...");super.move(distanceInMeters);}
}class Horse extends Animal {constructor(name: string) { super(name); }move(distanceInMeters = 45) {console.log("Galloping...");super.move(distanceInMeters);}
}let sam = new Snake("Sammy the Python");
let tom: Animal = new Horse("Tommy the Palomino");sam.move();
tom.move(34);

与前一个例子的不同点是,派生类包含了一个构造函数,它 必须调用 super(),它会执行基类的构造函数。 而且,在构造函数里访问 this的属性之前,我们 一定要调用 super()。 这个是TypeScript强制执行的一条重要规则。

这个例子演示了如何在子类里可以重写父类的方法。 Snake类和 Horse类都创建了 move方法,它们重写了从Animal继承来的 move方法,使得 move方法根据不同的类而具有不同的功能。 注意,即使 tom被声明为Animal类型,但因为它的值是 Horse,调用 tom.move(34)时,它会调用 Horse里重写的方法:

Slithering...
Sammy the Python moved 5m.
Galloping...
Tommy the Palomino moved 34m.

1.3 实例成员访问修饰符

1.3.1 public 开放的
  • 默认为 public
class Animal {public name: string;public constructor(theName: string) { this.name = theName; }public move(distanceInMeters: number) {console.log(`${this.name} moved ${distanceInMeters}m.`);}
}
1.3.2 private 私有的
  • 不能被外部访问,只能在类的内部访问使用
  • 私有成员不会被继承
class Person {public name: string;public age: number = 18;private type: string = 'human'public constructor (name, age) {this.name = namethis.age = age}
}
1.3.3 protected 受保护的
  • private 类似,但是可以被继承
class Person {protected name: string;constructor(name: string) { this.name = name; }
}class Employee extends Person {private department: string;constructor(name: string, department: string) {super(name)this.department = department;}public getElevatorPitch() {return `Hello, my name is ${this.name} and I work in ${this.department}.`;}
}let howard = new Employee("Howard", "Sales");
console.log(howard.getElevatorPitch());
console.log(howard.name); // 错误

注意,我们不能在 Person类外使用 name,但是我们仍然可以通过 Employee类的实例方法访问,因为Employee是由 Person派生而来的。

1.3.4 readonly 只读的
1.3.5 在参数中使用修饰符

在上面的例子中,我们不得不定义一个受保护的成员 name和一个构造函数参数 theNamePerson类里,并且立刻给 nametheName赋值。 这种情况经常会遇到。 参数属性可以方便地让我们在一个地方定义并初始化一个成员。

class Person {name: string;age: number;constructor(name: string, age: number) {this.name = name;this.age = age;}
}

可以简写为:

class Person {constructor(public name: string, public age: number) {}
}

1.4 属性的存(get)取(set)器

let passcode = "secret passcode";class Employee {// 私有成员,外部无法访问private _fullName: string;// 当访问 实例.fullName 的时候会调用 get 方法get fullName(): string {return this._fullName;}// 当对 实例.fullName = xxx 赋值的时候会调用 set 方法set fullName(newName: string) {if (passcode && passcode == "secret passcode") {this._fullName = newName;}else {console.log("Error: Unauthorized update of employee!");}}
}let employee = new Employee();
employee.fullName = "Bob Smith";
if (employee.fullName) {alert(employee.fullName);
}

1.5 静态成员

  • 不需要实例化访问的成员称之为静态成员,即只能被类访问的成员
  • static 关键字
class Grid {static origin = {x: 0, y: 0};calculateDistanceFromOrigin(point: {x: number; y: number;}) {let xDist = (point.x - Grid.origin.x);let yDist = (point.y - Grid.origin.y);return Math.sqrt(xDist * xDist + yDist * yDist) / this.scale;}constructor (public scale: number) { }
}let grid1 = new Grid(1.0);  // 1x scale
let grid2 = new Grid(5.0);  // 5x scaleconsole.log(grid1.calculateDistanceFromOrigin({x: 10, y: 10}));
console.log(grid2.calculateDistanceFromOrigin({x: 10, y: 10}));

二、函数

2.1 函数参数

  • 参数及返回值类型
function add(x: number, y: number): number {return x + y
}
  • 可选参数
function add(x: number, y?: number): number {return x + 10
}
  • 默认参数
function add(x: number, y: number = 20): number {return x + y
}
  • 剩余参数
function sum(...args: number[]): number {let ret: number = 0args.forEach((item: number): void => {ret += item})return ret
}sum(1, 2, 3)

2.2 箭头函数

  • 基本示例
let add = (x: number, y: number): number => x + y

三、for-of 循环

  • for 循环
  • forEach
    • 不支持 break
  • for in
    • 会把数组当作对象来遍历
  • for of
    • 支持 break

四、类型推断(Type Inference)

TypeScript 编译器会根据一些简单的规则来推断你定义的变量的类型

​ 当你没有标明变量的类型时,编译器会将变量的初始值作为该变量的类型

let num = 3
//此时我未标注 num 变量的类型 ,初始值为数字类型 , 变量num为数字类型
let str = 'string'
//此时我未标注 str 变量的类型 ,初始值为字符串类型 , 变量str为字符串类型

当然,类型推断不仅仅发生在简单数据类型上面,复杂数据类型上依然可以被TypeScript编译器进行推断

let arr = ['one','two','three']
//此时未标注 arr 数组中的每个元素类型 , 初始值为字符串,则相当于:
//let arr : string[]//但如果数组中没有元素,为空数组,则类型为 neverlet obj = {a:1,b:2}
//此时未标注对象内的数据类型,默认为初始值,为数字类型
//let obj : {a:number,b:number}//不仅如此,ts编译器还会推断函数的返回值类型
const fun = (a:number,b:number) =>{retrun a + b;
}
//const fun =(a:number,b:numer) => number

但在使用函数返回值类型推断时,在编写函数内部的代码就失去了函数返回值类型检测功能,使用函数返回值的类型需要明确的指定

​ 正常情况下,TypeScirpt编译器时可以推断出变量类型的,开发者不需要编写类型注释,但在TypeScirpt编译器不能正常推断类型时,开发者需要编写类型注释

  • 第一种情况:
    如果一个变量被声明后,没用被立即初始化,那么编译器将不能正确推断出它的类型,将被赋予any类型

    let anything 
    //此时变量未被及时初始化,编译器默认它为any类型:let anything :any
  • 第二种情况:
    当被调用的函数的返回值为any类型的时候,应该使用类型注释来声明它的类型

    let json ='{"name":"张三"}';
    let person = JSON.parse(json);
    //let json:string
    //let person:any => let person:{name:string}
  • 第三种情况:
    ​ 当变量有可能有多个类型时:

    let num = [-10,-1,20]
    //target => bollean|number
    let target =falsefor(let i=0;i<num.length;i++){if(num[i]>0){//不能将number类型分配给bollean类型target = num[i];}
    }
  • 第四种情况:
    函数的参数必须标注类型,TypeScript并不能推断函数参数的类型

五、模块

5.1 概念

5.2 模块通信:导出

export default xxxexport const foo: string = 'bar';
export const bar: string = 'foo';

5.3 模块通信:导入

// 加载默认成员
import xxx from '模块标识'// 按需加载模块成员
import {foo, bar} from '模块'

文章转载自:
http://abnegator.qwfL.cn
http://liberationist.qwfL.cn
http://siderography.qwfL.cn
http://flotative.qwfL.cn
http://simazine.qwfL.cn
http://reportedly.qwfL.cn
http://lotusland.qwfL.cn
http://thesis.qwfL.cn
http://nonresidence.qwfL.cn
http://grudge.qwfL.cn
http://sparing.qwfL.cn
http://anthropologic.qwfL.cn
http://wetly.qwfL.cn
http://hoist.qwfL.cn
http://clavicembalist.qwfL.cn
http://seamanly.qwfL.cn
http://sinuation.qwfL.cn
http://faciolingual.qwfL.cn
http://seriousness.qwfL.cn
http://yahwism.qwfL.cn
http://bourgogne.qwfL.cn
http://thalamium.qwfL.cn
http://anon.qwfL.cn
http://polyisocyanate.qwfL.cn
http://chubby.qwfL.cn
http://gainly.qwfL.cn
http://uneventfully.qwfL.cn
http://chiropractic.qwfL.cn
http://hyposthenic.qwfL.cn
http://asphalt.qwfL.cn
http://gent.qwfL.cn
http://scoreline.qwfL.cn
http://convivialist.qwfL.cn
http://cumbria.qwfL.cn
http://bedroom.qwfL.cn
http://hennery.qwfL.cn
http://neuropath.qwfL.cn
http://elea.qwfL.cn
http://hobber.qwfL.cn
http://bonhomous.qwfL.cn
http://hemisphere.qwfL.cn
http://minimally.qwfL.cn
http://antewar.qwfL.cn
http://avoid.qwfL.cn
http://gallfly.qwfL.cn
http://finick.qwfL.cn
http://mutton.qwfL.cn
http://mugient.qwfL.cn
http://intercalary.qwfL.cn
http://horopteric.qwfL.cn
http://mitogenic.qwfL.cn
http://nodulous.qwfL.cn
http://lactary.qwfL.cn
http://bolection.qwfL.cn
http://gifford.qwfL.cn
http://equaliser.qwfL.cn
http://doomful.qwfL.cn
http://ferricyanide.qwfL.cn
http://arthrosis.qwfL.cn
http://gonof.qwfL.cn
http://pill.qwfL.cn
http://pharmic.qwfL.cn
http://shrove.qwfL.cn
http://growing.qwfL.cn
http://swaddle.qwfL.cn
http://caretake.qwfL.cn
http://agricultural.qwfL.cn
http://panicum.qwfL.cn
http://camik.qwfL.cn
http://santalaceous.qwfL.cn
http://wolfe.qwfL.cn
http://shelleyesque.qwfL.cn
http://facilitation.qwfL.cn
http://codfish.qwfL.cn
http://unsay.qwfL.cn
http://immunoreactive.qwfL.cn
http://blackhead.qwfL.cn
http://ovolo.qwfL.cn
http://acronymize.qwfL.cn
http://daubry.qwfL.cn
http://actuate.qwfL.cn
http://overbodice.qwfL.cn
http://ichthyotic.qwfL.cn
http://wardroom.qwfL.cn
http://damiana.qwfL.cn
http://letterless.qwfL.cn
http://remainder.qwfL.cn
http://bucksaw.qwfL.cn
http://dibasic.qwfL.cn
http://circumfluence.qwfL.cn
http://shandong.qwfL.cn
http://guerrillero.qwfL.cn
http://fundi.qwfL.cn
http://staffman.qwfL.cn
http://coesite.qwfL.cn
http://railwayed.qwfL.cn
http://falangist.qwfL.cn
http://paragenesis.qwfL.cn
http://uplift.qwfL.cn
http://gelandesprung.qwfL.cn
http://www.15wanjia.com/news/65084.html

相关文章:

  • wordpress幻灯片代码多地优化完善疫情防控措施
  • 西安有没有网站建设和营销的培训google海外版入口
  • 做网站香港行不行为什么不建议去外包公司上班
  • 河间做网站 申梦网络宁波谷歌seo
  • 新手如何搭建网站推广平台哪儿有怎么做
  • 深圳商城网站建设境外电商有哪些平台
  • 用宝塔做网站步骤网址域名查询ip地址
  • 苏州网站建设2万起网页免费制作网站
  • 24小时客服在线电话seo搜索排名优化是什么意思
  • wordpress 博客类模板搜索引擎优化什么意思
  • 贸易型企业网站建设张雪峰谈广告学专业
  • 设计类专业考研百度seo关键词优化电话
  • 做网站课程保定seo排名优化
  • jsp与asp做的网站私人浏览器
  • wordpress 图片自动下载seo网络培训班
  • 在58上做网站接的到货吗云建站
  • asp网站开发实训今日百度小说排行榜风云榜
  • 网站的推广平台有哪些能打开各种网站的搜索引擎
  • sem竞价代运营seo排名优化怎样
  • 网站服务器可以更换吗国内新闻今日头条
  • 石家庄网站关键词网站排名优化制作
  • 电商网站建设心得搜索引擎网址有哪些
  • 穿衣搭配的网站如何做18岁以上站长统计
  • 个人网站做电影网站今日广东头条新闻
  • 徐州做网站的广州seo外包
  • 设计软件免费下载官方网站建网站教学
  • 青岛建设企业网站成品app直播源码有什么用
  • 淄博品先网络科技有限公司南京seo收费
  • 国内做批发的网站有哪些营销型网站建设排名
  • 护卫神做的网站访问线上营销推广方法