function Person(){
this.run1 = function(){
}
}
Person.run2 = function(){
Person.name = "哈哈哈哈"
}
var p = new Person();
p.run1();
Person.run2();
Person.name;
function $(element){
return new Base(element);
}
$.get = function(){
}
function Base(element){
this.element = 获取当前节点;
this.css = function(arr, value){
this.element.style.arr = value
}
}
$('#box').css('color', 'red')
$.get('url', function(){
})
class Person{
public name:string;
public age:number = 20;
static age1:number = 20;
constructor(name:string){
this.name = name;
}
run(){
alert(`${this.name}在运动`);
}
work(){
alert(`${this.name}在工作`)
}
static print() {
alert('print方法')
}
}
var p = new Person('张三');
p.run();
Person.print();
Person.age1;
class Animal{
name:string;
constructor(name:string){
this.name = name;;
}
eat(){
console.log('吃的方法');
}
}
class Dog extends Animal{
constructor(name:string){
super(name)
}
eat(){
return this.name + '吃肉';
}
}
class Cat extends Animal{
constructor(name:string){
super(name)
}
eat(){
return this.name + '吃鱼';
}
}
abstract class Animal1{
public name:string;
constructor(name:string){
this.name = name;
}
abstract eat():any;
run(){
console.log('其他方法可以不实现');
}
}
class Dog1 extends Animal1{
constructor(name:any){
super(name)
}
eat(){
console.log(this.name + "吃肉");
}
}
var d = new Dog('小花花');
d.eat();
function printLabel():void{
console.log('pringLavel');
}
printLabel();
function printLabel1(label:string):void{
console.log('pringLavel1');
}
printLabel1('哈哈');
function printLabel2(labelInfo:{label:string}):void{
console.log('printLabel2');
}
printLabel2({label: '哈哈哈'})
interface FullName{
firstName:string;
secondName:string;
}
function printName(name:FullName){
console.log(name.firstName + '----------' + name.secondName);
}
printName({
firstName: '漳卅',
secondName: "风水地"
})
var obj = {
age:20,
firstName: '张',
secondName: '三'
}
printName(obj)
interface FullName1{
firstName:string;
secondName?:string;
}
function getName(name:FullName1) {
console.log(name);
}
getName({
secondName: '三',
firstName:'张'
})
getName({
firstName:'张'
})
|