[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 ...
随机推荐
- Sitecore 8.2 安全性第2部分:安全性编辑器和Access Viewer
在Sitecore中使用安全性时,您可以使用两个主要应用程序:安全编辑器和Access Viewer.从表面上看,这些工具看起来很相似,但它们扮演着截然不同的角色.让我们回顾一下每个应用程序以及它们的 ...
- python 知识回顾
第一章:搭建编程环境1.在Windows系统中搭建Python编程环境. 1.1 安装Python 访问http://python.org/downloads/ ,点击下载到本地,后安装. 1.2安装 ...
- 乘法器——基于Wallace树的4位乘法器实现
博主最近在学习加法器乘法等等相关知识,在学习乘法器booth编码加Wallace树压缩时,发现在压缩部分积的时候用到了进位保留加法器(Carry Save Adder),博主对这种加法器不是很理解,而 ...
- C++ 数组输出
C++中输出数组数据分两种情况:字符型数组和非字符型数组 当定义变量为字符型数组时,采用cout<<数组名; 系统会将数组当作字符串来输出,如: ]={'}; cout << ...
- typescript nodejs 依赖注入实现
依赖注入通常也是我们所说的ioc模式,今天分享的是用typescript语言实现的ioc模式,这边用到的主要组件是 reflect-metadata 这个组件可以获取或者设置元数据信息,它的作用是拿到 ...
- python3.6安装pyinstaller报错:AttributeError: module 'enum' has no attribute 'IntFlag'
转载至:https://blog.csdn.net/qq_41185868/article/details/80599336 感谢原作者的分享 解决思路:这可能是由包Enum34引起的.因为Pytho ...
- Java自学-接口与继承 final
Java的修饰符final final修饰类,方法,基本类型变量,引用的时候分别有不同的意思. 示例 1 : final修饰类 当Hero被修饰成final的时候,表示Hero不能够被继承 其子类会出 ...
- javascript中的vavigator对象
appCodeName javaScript 1.0 介绍:与浏览器相关的内部代码名 appMinorVersion IE4及其后续的版本 介绍:辅版本号(通常应用于浏览器的补丁或服务包) appNa ...
- js中函数的参数为函数的情况即回调函数
js中函数的参数可以是数组对象也可以是函数,当参数为函数时我们叫做回调函数 //定义回调函数function B() { console.log("函数B")setTimeout( ...
- 冬虫夏草winterwormsummerherb英语
“中药之王”--冬虫夏草WinterwormSummerherb King of Chinese medicine --WinterwormSummerherb “冬天是虫,夏天是草,冬虫夏草是个宝. ...