Skip to content
Navigation Menu
Sign in
Products
Platform
GitHub
Repository hosting, code review, and collaboration
Copilot
AI coding agent for tasks, projects, and automated work
Build & Ship
Actions
CI/CD and automation
Code Quality
Quality analysis, fixes, and enforcement
Codespaces
Cloud development environments
Secure
Code Security
Vulnerability detection and remediation
Secret Protection
Secret scanning and leak prevention
All Features
Developers
Learn
Documentation
Training
Certifications
Build
Build with Copilot
Customize Copilot
Integrations
Explore
Trending repos
GitHub Sponsors
Developer articles
Changelog
Changelog
Your source for the latest features, improvements, and fixes across GitHub products, all in one place.
Businesses
By Stage
Enterprises
Team
Startups
Nonprofits
By Industry
Healthcare
Financial services
Manufacturing
Government
See all industries
Evaluate GitHub
Why GitHub
Customer Stories
Business insights
Trust Center
Add-ons
GitHub Advanced Security
Enterprise-grade code security
Copilot for business
Enterprise-grade AI features
Premium Support
Enterprise-grade 24/7 support
Resources
Learn & Connect
Documentation
Resource center
Blog
Events & webinars
Community Forum
Customer Stories
Integrations
Support
Customer support
Training
GitHub Status
Company
About
Partners
Changelog
GitHub Universe
GitHub Universe
The event for developers, by developers — talks, workshops, and what’s next for GitHub.
Pricing
Search
/
Sign in
Sign up
Appearance settings
You signed in with another tab or window.
Reload
to refresh your session.
You signed out in another tab or window.
Reload
to refresh your session.
You switched accounts on another tab or window.
Reload
to refresh your session.
Dismiss alert
{{ message }}
ObjectJS
oop
Repository navigation
Code
Issues
Pull requests
Actions
Projects
Wiki
Security and quality
Insights
More
items
Innovations
Jump to bottom
Edit
New page
goto100 edited this page
Jul 22, 2013
·
3 revisions
oop.js 的特点
唯一针对语言层面的 oop 解决方案库
js oop 解决方案很多,但基本都是随着某一流行的库一起发布,没有独立版本,各个库的方案也不兼容,如 Mootools、Ext、dojo 等;
只解决语言层面的问题,不包含上层绑定,却为上层绑定提供了很多功能,应用场景广泛;
隐藏 prototype
个人认为,在 js 的学习曲线中,原型继承是 js 中最晦涩难懂的部分,一个写了几年 js 的程序员如都可能没有掌握;
oop.js 实现继承的原理依然是传统的原型继承;
oop.js 对原型继承做了全面的封装,在正常使用情况下不会出现
prototype
关键字;
名称一次定义
提高开发体验,降低维护成本;
在 oop.js 中所有涉及到命名的东西都是一次定义,保持代码整洁;
在定义类时只出现一次类名;
在调用父类同名方法时不用书写同名方法;
方法可以获得到自己的名字,为上层代码提供了命名一次定义的灵活性(比如自动fire同名事件);
和 loader 结合后,类也可以获得自己的名字;
方法访问
oop.js 中不存在单独的类方法或实例方法,所有方法定义后都可以在类和实例上调用,区别是调用传递参数的不同;
模仿 python;
此设计也是为了隐藏
prototype
关键字而做的;
可以通过 metaclass 关闭此特性;
实例方法默认参数
self
降低维护成本;
oop.js 通过实例方法的第一个参数
self
传递实例的引用,
this
关键字在 oop.js 中被赋予了其他意义;
目的是避免
var self = this
带来的脏代码和维护成本的升高;
在 node 平台下测试,所有实例方法嵌套会带来一个比较稳定的性能损耗;
可以通过 metaclass 关闭此特性;
Wiki pages
Pages
3
Loading
Home
Uh oh!
There was an error while loading.
Please reload this page
.
Loading
Innovations
Uh oh!
There was an error while loading.
Please reload this page
.
Loading
vs_kissy_Base
Uh oh!
There was an error while loading.
Please reload this page
.
Add a custom sidebar
Clone this wiki locally
You can’t perform that action at this time.