[Javascript] Working with Static Properties on a Class
Classes are syntactic sugar over functions and functions are also referred to as "callable" objects. So it is possible to treat a function like an object and give them key / value properties like objects. The static keyword gives us the ability to assign a key / value property to a class itself, not an instance of that class. This lesson will walk you through using the static keyword and even show how to replicate it with regular functions.
class Retangle{
static callRectangle(){
return 'hello world'
}
}
const myShape = new Rectangle()
console.log(myShape.callRectangle) // error, you cannot call static prop on instance
But static prop can be called from child class:
function Rectangle(){
}
Rectangle.callRectangle = function(){
return 'hello world'
}
class Square extends Rectangle {
static whoAmI(){
return "Hello, all " + super.callRectangle()
}
}
console.log(Square.whoAmI()) //Hello, all hello world
[Javascript] Working with Static Properties on a Class的更多相关文章
- ES-Next classes static properties
ES-Next classes static properties https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/ ...
- 在JavaScript文件中读取properties文件的方法
假设有JavaScript文件叫做:readproperties.js,这个文件需要读取config.properties这个配置文件,步骤如下: 1. 下载插件jquery.i18n.proper ...
- JavaScript Patterns 5.7 Object Constants
Principle Make variables shouldn't be changed stand out using all caps. Add constants as static prop ...
- javascript oo实现(转)
javascript oo实现 By purplebamboo 7月 13 2014 更新日期:8月 21 2014 文章目录 1. 原始时代最简单的oo实现 2. 石器时代的oo实现 3. 工业时代 ...
- Passing JavaScript Objects to Managed Code
Silverlight If the target managed property or input parameter is strongly typed (that is, not typed ...
- JBoss EAP6/AS7/WildFly: How to Use Properties Files Outside Your Archive--reference
Introduction I’d like to preface this post with, really, all properties files should be inside your ...
- 转:javascript面向对象编程
作者: 阮一峰 日期: 2010年5月17日 学习Javascript,最难的地方是什么? 我觉得,Object(对象)最难.因为Javascript的Object模型很独特,和其他语言都不一样,初学 ...
- SpringBoot标准Properties
# =================================================================== # COMMON SPRING BOOT PROPERTIE ...
- spring boot application.properties 属性详解
2019年3月21日17:09:59 英文原版: https://docs.spring.io/spring-boot/docs/current/reference/html/common-appli ...
随机推荐
- 分享一个Linux C++消息通信框架TCPSHM
由于本人从事行业关系,Linux环境下的低延迟通信是我关注的技术之一.要达到极端的低延迟,当然同机器内IPC比网络通信快,而Linux IPC方式中无疑是共享内存延迟最低.不过相对于TCP这种通用的通 ...
- Linux文件目录指令
1.pwd指令 pwd 显示当前所在的目录 2.ls指令 ls [选项] [目录或文件] 查看文件信息 ls -a 查看所有文件和目录,包括隐藏的 ls -l 以列表的方式显示 3.cd指令 cd 路 ...
- SQL系列(十三)—— 关于表的DDL
前面的文章一直都在讲述关于DML方面的SQL Statement.这篇文章来说说表方面的DDL: CREATE 创建表 ALTER 修改表 DROP 删除表 CREATE 1.语法 CREATE TA ...
- mysql给某个用户单个表权限
CREATE USER systemselect IDENTIFIED BY 'Zbank123456';#只给查询权限 GRANT SELECT ON szkitil.zbank_businesss ...
- JAAS configuration for Kafka clients
Clients may configure JAAS using the client configuration property sasl.jaas.config or using the sta ...
- GIT VI操作汇总
在Git Bash Here中用命令行 pull\push\merge 代码,如果存在冲突或者自动合并时,会自动进入VI界面 1.按下 ESC 键,退出编辑模式,切换到命令模式. 2.输入 :wq , ...
- Grafana官方和社区提供的dashboard
详见:https://grafana.com/grafana/dashboards 可以在左侧配置筛选条件,非常强大. 当然Grafana中所有的Dashboard通过JSON进行共享,下载并且导入这 ...
- Julie D. Saba:儿童肿瘤学是一个令人惊奇的领域
编者按 作为一名儿童肿瘤学家,工作中充满了挑战与机遇.近几十年来,世界各地的儿童肿瘤的发病率呈持续上升的趋势.许多人认为这不仅是由于诊断水平的提高,而且是因为儿童肿瘤的潜在风险也确实在增加.据英国儿童 ...
- springmvc处理json数据
springMVC提供了处理JSON格式请求/响应的HttpMessageConverter MappingJckson2HttpMessageConverter利用Jackson开源类包处理JSON ...
- 【转载】Windows系统电脑通过命令msinfo32查看系统信息
在Windows操作系统中,可以使用msinfo32的操作命令查看操作系统相关信息,通过msinfo32命令可以查看到系统摘要,包括硬件资源.组件.软件环境等系统信息.其中系统摘要包括冲突/共享.DM ...