无类继承.key

Similar documents
Microsoft Word - 01.DOC

新・解きながら学ぶJava

EJB-Programming-3.PDF

Microsoft Word - ch04三校.doc

EJB-Programming-4-cn.doc

Chapter 9: Objects and Classes

OOP with Java 通知 Project 4: 4 月 18 日晚 9 点 关于抄袭 没有分数

OOP with Java 通知 Project 4: 4 月 19 日晚 9 点

untitled

Strings

威 福 髮 藝 店 桃 園 市 蘆 竹 區 中 山 里 福 祿 一 街 48 號 地 下 一 樓 50,000 獨 資 李 依 純 105/04/06 府 經 登 字 第 號 宏 品 餐 飲 桃 園 市 桃 園 區 信 光 里 民

(TestFailure) JUnit Framework AssertionFailedError JUnit Composite TestSuite Test TestSuite run() run() JUnit

KillTest 质量更高 服务更好 学习资料 半年免费更新服务

SDK 概要 使用 Maven 的用户可以从 Maven 库中搜索 "odps-sdk" 获取不同版本的 Java SDK: 包名 odps-sdk-core odps-sdk-commons odps-sdk-udf odps-sdk-mapred odps-sdk-graph 描述 ODPS 基


软件工程文档编制

OOP with Java 通知 Project 3: 3 月 29 日晚 9 点 4 月 1 日上课

Microsoft Word - 物件導向編程精要.doc

标题

Java

Microsoft Word - Learn Objective-C.doc

OOP with Java 通知 Project 4: 5 月 2 日晚 9 点

Microsoft PowerPoint - ch6 [相容模式]

untitled

Microsoft Word - 第3章.doc

1 1 大概思路 创建 WebAPI 创建 CrossMainController 并编写 Nuget 安装 microsoft.aspnet.webapi.cors 跨域设置路由 编写 Jquery EasyUI 界面 运行效果 2 创建 WebAPI 创建 WebAPI, 新建 -> 项目 ->

Java java.lang.math Java Java.util.Random : ArithmeticException int zero = 0; try { int i= 72 / zero ; }catch (ArithmeticException e ) { // } 0,

1 Framework.NET Framework Microsoft Windows.NET Framework.NET Framework NOTE.NET NET Framework.NET Framework 2.0 ( 3 ).NET Framework 2.0.NET F

KillTest 质量更高 服务更好 学习资料 半年免费更新服务

Chapter 9: Objects and Classes

Fun Time (1) What happens in memory? 1 i n t i ; 2 s h o r t j ; 3 double k ; 4 char c = a ; 5 i = 3; j = 2; 6 k = i j ; H.-T. Lin (NTU CSIE) Referenc

untitled

KillTest 质量更高 服务更好 学习资料 半年免费更新服务

由社會發展趨勢探討國人睡眠品質


AM101-1(中文)11.cdr

Microsoft Word - 1HF12序.doc

Microsoft Word - 讀報看科普─人體篇_橫_.doc

鍟嗗搧瑙傚療鈥㈤挗鏉

席 远 杨 一 人 了, 正 当 她 开 枪 时 却 发 现 子 弹 没 了 该 死, 只 能 赤 手 空 拳 了 洛 水 云 与 席 远 杨 交 起 手 来, 洛 水 云 出 手 招 招 致 命 想 那 席 远 杨 也 不 是 泛 泛 之 辈, 很 快 掌 握 了 洛 水 云 出 招 路 数 看

閱 讀 素 材 V.S 分 組 方 式 的 差 異 化 教 學 工 具 表 班 級 :( ) 閱 讀 素 材 V.S 分 組 方 式 獨 立 閱 讀 夥 伴 閱 讀 ( 同 質 性 ) 夥 伴 閱 讀 ( 異 質 性 ) 友 善 陪 伴 虛 心 受 教 國 語 日 報 新 聞 生 活 文 藝 兒 童

Microsoft Word - 2B802內文.doc

東區校園中法治教育種子師資教學研習營

OOP with Java 通知 Project 3 提交时间 3 月 29 日晚 9 点 Piazza Project 2 投票

<4D F736F F F696E74202D20332D322E432B2BC3E6CFF2B6D4CFF3B3CCD0F2C9E8BCC6A1AAD6D8D4D8A1A2BCCCB3D0A1A2B6E0CCACBACDBEDBBACF2E707074>

第 一 节 认 识 自 我 的 意 义 一 个 人 只 有 认 识 自 我, 才 能 够 正 确 地 认 识 到 自 己 的 优 劣 势, 找 出 自 己 的 职 业 亮 点, 为 自 己 的 顺 利 求 职 推 波 助 澜 ; 一 个 人 只 有 认 识 自 我, 才 能 在 求 职 中 保 持

前言 C# C# C# C C# C# C# C# C# microservices C# More Effective C# More Effective C# C# C# C# Effective C# 50 C# C# 7 Effective vii

ASP.NET MVC Visual Studio MVC MVC 範例 1-1 建立第一個 MVC 專案 Visual Studio MVC step 01 Visual Studio Web ASP.NET Web (.NET Framework) step 02 C:\M

Microsoft PowerPoint - L17_Inheritance_v4.pptx

エスポラージュ株式会社 住所 : 東京都江東区大島 東急ドエルアルス大島 HP: ******************* * 关于 Java 测试试题 ******

Learning Java

文档 3

mvc

untitled

untitled

<ADB6ADB1C25EA8FAA6DB2D4D56432E706466>

javaexample-02.pdf

BOOL EnumWindows(WNDENUMPROC lparam); lpenumfunc, LPARAM (Native Interface) PowerBuilder PowerBuilder PBNI 2

Microsoft Word - 第6章.doc

untitled

RUN_PC連載_8_.doc

概述

Microsoft Word - 把时间当作朋友(2011第3版)3.0.b.06.doc

使 用 Java 语 言 模 拟 保 险 箱 容 量 门 板 厚 度 箱 体 厚 度 属 性 锁 具 类 型 开 保 险 箱 关 保 险 箱 动 作 存 取 款

新版 明解C++入門編

CHAPTER VC#

WWW PHP

9, : Java 19., [4 ]. 3 Apla2Java Apla PAR,Apla2Java Apla Java.,Apla,,, 1. 1 Apla Apla A[J ] Get elem (set A) A J A B Intersection(set A,set B) A B A B

第一章 章标题-F2 上空24,下空24

untitled

關於本書 l 3 PhoneGap Appcelerator Titanium Sencha Touch (wrapper framework) Native App PhoneGap Build Native App Hybrid App Java Objective-C Android SDK

untitled

untitled

任務二 : 產生 20 個有炸彈的磚塊, 放在隨機的位置編輯 Block 類別的程式碼 import greenfoot.; // (World, Actor, GreenfootImage, Greenfoot and MouseInfo) Write a description of class

附录J:Eclipse教程

Swing-02.pdf

Strings

02

ii Vue Bootstrap 4 ES 6 Vue Vue Bootstrap 4 ES 6 Vue 2 vue html vue html vue Vue HTML 5 CSS ES 6 HTML 5 CSS Visual Studio Code h

C 1

1: public class MyOutputStream implements AutoCloseable { 3: public void close() throws IOException { 4: throw new IOException(); 5: } 6:

Factory Methods

RunPC2_.doc

《大话设计模式》第一章

第七讲 继承与多态

Microsoft Word - chap10.doc

OOP with Java 通知 Project 4: 5 月 2 日晚 9 点

Microsoft Word - 新1-12.doc

Windows RTEMS 1 Danilliu MMI TCP/IP QEMU i386 QEMU ARM POWERPC i386 IPC PC104 uc/os-ii uc/os MMI TCP/IP i386 PORT Linux ecos Linux ecos ecos eco

Microsoft Word - 把时间当作朋友(2011第3版)3.0.b.07.doc

北 风 网 讲 师 原 创 作 品 ---- 仅 供 学 员 内 部 交 流 使 用 前 言 吾 尝 终 日 而 思 矣, 不 如 须 臾 之 所 学 也 ; 吾 尝 跂 而 望 矣, 不 如 登 高 之 博 见 也 登 高 而 招, 臂 非 加 长 也, 而 见

06-4.indd

ebook50-15

FY.DOC

(procedure-oriented)?? 2

<4D F736F F D20A578A4E9AFABAAC0A46AA4A3A650A277AEE7B6E9A9BEAF50AFA85653A5F1A8A3BD5FB2FCA46AAAC02E646F63>

(6) 要 求 付 款 管 理 员 从 预 订 表 中 查 询 距 预 订 的 会 议 时 间 两 周 内 的 预 定, 根 据 客 户 记 录 给 满 足 条 件 的 客 户 发 送 支 付 余 款 要 求 (7) 支 付 余 款 管 理 员 收 到 客 户 余 款 支 付 的 通 知 后, 检

2009年3月全国计算机等级考试二级Java语言程序设计笔试试题

Microsoft PowerPoint - plan08.ppt

3. 反 映 : 4. 五 花 八 门 : 5. 慷 慨 : 6. 参 与 : 7. 慰 劳 : 8. 延 续 : 9. 珍 爱 : 10. 浪 漫 : 三. 找 出 下 列 每 组 词 中 的 近 义 词 或 同 义 词 : 节 日 节 气 节 令 时 节 习 俗 民 俗 仪 式 风 俗 文 献

Transcription:

无类继承 JavaScript 面向对象的根基 周爱 民 / aimingoo aiming@gmail.com https://aimingoo.github.io https://github.com/aimingoo

rand = new Person("Rand McKinnon",... https://docs.oracle.com/cd/e19957-01/816-6408-10/object.htm#1193255 https://www.fi.muni.cz/~xdohnal/manuals/jscript/toc.html

function car(make, model, year) { this.make = make; this.model = model;... https://docs.oracle.com/cd/e19957-01/816-6408-10/object.htm#1193255 https://www.fi.muni.cz/~xdohnal/manuals/jscript/toc.html

JavaScript 1.1 prototype based

function MyObject() { this.xxx =...... } MyObject.prototype = new Object(); MyObject.prototype.constructor = MyObject;... obj = new MyObject(); obj.x = 100;

Object() prototype.tostring().xxx proto MyObject() prototype.constructor proto obj x: 100 console.log(obj.x); console.log(obj.xxx); console.log(obj.tostring());

原型继承 类抄写 声明 : 类 / 原型 / 对象... 类继承 js1.1 ~ 1.x js2 ECMAScript edition 1~4

ECMAScript Ed5 Non-classes based

Object.hasOwnProperty(obj,...) Object.defineProperty(obj,...) Object.freeze() Object.XXXX()...

obj = Object.create(X, {... })

Object.setPrototypeOf(obj, X)

X.isPrototypeOf(obj)

X.isPrototypeOf(obj) vs. obj instanceof Object

1. 对象就是属性包 1 2 所以原型继承就是属性包的链式访问 所以可以没有类继承 ( 例例如构造器器和 new) an object is a collection of properties

JavaScript 2015 ECMAScript Ed 6 / ES6 该来的总会来的 崔椭圆 @2020

let obj = { name: 'obj', foo() {... } }

homeobj = Method[[HomeObject]]; super = Object.getPrototypeOf(homeObj)

let obj = { foo() { // 所以这 是静态声明 初始器赋值 console.log(super.name, this.name); } } Object.setPrototypeOf(obj, {name: 'Super'}); obj.name = 'obj'; obj.foo(); // Super, obj let obj2 = Object.create(obj, {name: 'I am obj2'}); obj2.foo(); // Super, I am obj2

let foo = obj.foo; foo(); //???,???

Class is appearances

class MyClass extends X { constructor() {.. } static foo() {.. } more() {...

class MyClass extends X { constructor() { super();.. } static foo() {.. } more() {..... // bind classname and set prototypes MyClass = asclassconstructor(constructor); Object.setPrototypeOf(MyClass, X); Object.setPrototypeOf(MyClass.prototype, X.prototype); = // for static methods sethomeobject(foo, MyClass); // for constructor and instance methods sethomeobject(constructor, MyClass.prototype); sethomeobject(more, MyClass.prototype);

class MyClass {} class MyClass extends X {}

class MyClass { constructor() { } } // no "super()" class MyClass extends X { constructor(...args) { // default super(...args); } }

> class MyClass extends null {} > obj = new MyClass; TypeError: Super constructor null of > Object.setPrototypeOf(MyClass, Object) > typeof(obj = new MyClass) 'object'

new X New or create

Base() prototype.tostring().xxx function MyObject() {} MyObject.prototype = new Base(); MyObject.prototype.foo =... proto MyObject() prototype.constructor proto obj = new MyObject; obj foo:...

function MyObject() {} MyObject.prototype = new Base(); MyObject.prototype.foo =... obj = new MyObject; class MyClass extends Base { constructor() {... foo() {...... obj2 = new MyClass; Base() constructor { _this = new_instance() setprototypeof(_this, new.target.prototype); // binding <this> or return... } MyClass() constructor { super(); // with new.target...... obj2 is <_this> obj2 obj2 = new MyClass; obj2.foo();

// success class MyDate extends Date {... // fail MyFunction.prototype = Function; } MyDate.prototype = new Date();... // success class MyFunction extends Function {... }

class MyClass extends X; 1 2 父类 X 是可以通过写类的原型来重置的 super 总是通过计算指向 X, 并受上述重置影响 obj = new MyClass; 1 obj 总是由祖先类 (Base) 创建的实例例

Atom Meta based

X = Object.create(null); Object.setPrototypeOf(X null);

function isatom(obj) { let types = {object: true, function: true}; if (types[typeof obj]) { return!(obj instanceof Object); } return false; }

arguments namespace // for arguments args = Function('return arguments')(); isatom(args); // true // for namespace import * as namespace from "./exports.mjs"; isatom(namespace); // true

atom 原 子 meta 元 能产 生原 子的 一个过程 Meta - 能产 生meta的 一个过程 称为元类型 MetaClass - 如果所产 生的meta是 一个类 则这个Meta称为元类类型 // 如下代码意味着Atom()是元函数或元构造器器 atom = new Atom();

// a meta/atom-constructor, derived from null, it s meta style class meta extends null {...

// Atom() for meta system class Atom extends null { constructor() { return Object.create(new.target.prototype); } }

// Atom() for meta system class Atom... // Meta class Meta extends null { constructor() { return Object.setPrototypeOf( class extends new.target{}, Atom); } }

// Atom() for meta system class Atom... // Meta class Meta... // to atom style void Object.setPrototypeOf(Atom, null); void Object.setPrototypeOf(Meta, null);

// Atom() for meta system class Atom... // Meta class Meta... // to atom style... // Meta Classes class MetaClass extends Meta { static isclassof(x) { return x instanceof this x.prototype instanceof this; } }

// Atom() for meta system class Atom... // Meta class Meta... // to atom style... // Meta Classes class MetaClass extends Meta {... class MetaObject extends new MetaClass {} x = new MetaObject;

> [MetaObject, MetaClass, Meta, Atom, x].foreach(x=>console.log(isatom(x))); true true true true true > typeof x 'object'

class Meta class MetaClass class MetaObject extends new MetaClass {} class MetaX extends MetaClass {} Meta (元类型) extends extends class MetaObjectEx extends MetaObject {} obj = new MetaObject; obj2 = new MetaObjectEx; MetaClass (元类) MetaX (派 生类) Meta-class instantiation Meta based ECMAScript based MetaObject (实例例类) instanceof is 'true' extends MetaObjectEx obj instanceof is 'true' obj2

> Meta.isAtom(null); true > Meta.isAtom(Object.prototype); true

> Objext = Meta.from(Object);

atom Object.prototype > Objext = Meta.from(Object); > Objext.keys(new Objext); [] Atom Meta MetaClass MetaObject Objext = Object

Ox bje t github.com/aimingoo/metameta