[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 ...
随机推荐
- Matlab数据标准化——mapstd、mapminmax
Matlab神经网络工具箱中提供了两个自带的数据标准化处理的函数——mapstd和mapminmax,本文试图解析一下这两个函数的用法. 一.mapstd mapstd对应我们数学建模中常使用的Z-S ...
- @Autowired注解到底是byType还是byName?
2016-08-05 14:29:32 杨家昌 阅读数 13400更多 分类专栏: spring 版权声明:本文为博主原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接和本声明 ...
- 史上最全HashMap红黑树解析
HashMap红黑树解析 红黑树介绍 TreeNode结构 树化的过程 红黑树的左旋和右旋 TreeNode的左旋和右旋 红黑树的插入 TreeNode的插入 红黑树的删除 TreeNode的删除节点 ...
- java之maven之maven的使用
这里使用的工具是 myeclipse ,所以这里讲的是在 myeclipse 上使用maven. 1.什么是仓库? 用于存放依赖包.配置文件.其他插件等. 项目添加依赖时,默认从 本地仓库 读取依赖包 ...
- SpringBoot与SpringDateJPA和Mybatis的整合
一.SpringBoot与SpringDateJPA的整合 1-1.需求 查询数据库---->得到数据------>展示到页面上 1-2.整合步骤 1-2-1.创建SpringBoot工程 ...
- webpack 里的 import, exports 实现原理
在使用 webpack 对脚本进行打包, 在开发中, 每个文件中都会使用 import 语句来导入一些功能,又会使用 export 语句导出一些功能,为了研究 import 和 export 原理,研 ...
- Serverless
一.介绍 是指依赖于第三方应用程序或服务来管理服务器端逻辑的应用程序. 此类应用程序是基于云的数据库(如Google Firebase)或身份验证服务. 无服务器也意味着开发为事件触发的代码,并且在无 ...
- 滥用exchage远程调用域管理员API接口
0x00 前言 在大多数的Active Directory和Exchange中,Exchange服务器具有很高的权限,即Exchange服务器上的管理员可以很容易地将权限提升到域管理员权限,我在zdi ...
- linux rwx 权限说明
Linux的文件和目录的权限,有RWX三种. r(Read,读取):对文件而言,具有读取文件内容的权限:对目录来说,具有浏览目录的权限. w(Write,写入):对文件而言,具有新增,修改,删除文件内 ...
- FastJson实现复杂对象序列化与反序列化
原文:http://blog.csdn.net/xqhadoop/article/details/62217954 一.认识FastJson 1.优势 fastjson是目前java语言中最快的jso ...