callSuper in kissy

Post on 12-Sep-2014

274 views 1 download

Tags:

description

implement super in KISSY

Transcript of callSuper in kissy

callSuper in KISSY

yiminghe@gmail.com

承玉

Super

• Call super class method from sub class method with same signature.

Super in other language

• Java

• constructor default super()

– keyword

base() sub()

Super in other language

• Java

• Constructor Explicit call super

– Must be on first line

– keyword

base(int i) sub()

Super in other languages

• Java

• Explicit call super.xx in overriden method

– object

sub run() base run()

Super in other languages

• Python

• Super

– Build-in bind function( mro )

– Constructor is same with method

• No first line constraint

• Allow multiple inheritance

Base init Sub init Sub run Base run

Super in other languages

• JavaScript

• But flexible

Super in KISSY

• KISSY

– Build own class system

Super in KISSY

• callSuper

• Built-in bind function (~python)

• No need to specify method name

• Does not allow multiple inheritance – Extensions(Mixins) + single Inheritance + plugin

Usage

Base init M1 init Sub init Sub run Base run Sub destroy M1 destroy Base destroy

Bind usage

• Closure?

internal

• arguments.callee.caller

• __owner__/__name__

Acknowledgements

• goto100(义宇)