typescript7 拓展全局变量

///

//ts7

// 如何扩展 全局变量 局部变量类型

declare global{

interface String{

double():string;

}

 

interface Window{

myname:string;

}

}

 

String.prototype.double = function(){

return this + this

}

console.log('hello'.double())

 

// 模块内扩展全局变量declare global

 

export{ }

// 合并声明 同一个名称的两个独立声明 会合并成一个单一声明

// interface 可以作为一个类型来使用

// 不加export的 相同类型里面的属性都会被合并了


 

// 通过命名空间扩展类

class Form{

username:Form.Item = '';

password:Form.Item = ''

}

namespace Form{

//扩展了一个Item 属性

export class Item1 {}

class Item2 {}// 不导出 外面用不了

}



 

declare function jQuery(selector:string):any;

declare namespace jQuery2 {

export let name:string;

}

  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值