[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 ...
随机推荐
- docker封装mysql镜像
一.概述 直接使用官方的镜像 docker pull mysql:5.7 但是mysqld.cnf并没有优化,还是默认的. 二.封装镜像 创建目录 # dockerfile目录 mkdir -p /o ...
- Java学习:等待唤醒机制
等待唤醒机制 线程的状态 NEW 至今尚未启动的线程处于这种状态 RUNNABLE 正在Java虚拟机中执行的线程处于这种状态 BLOCKED 受阻塞并等待某个监视器锁的线程处于这种状态 WA ...
- c# 基本类型存储方式的研究
基本单位 二进制,当前的计算机系统使用的基本上是二进制系统.二进制的单位是位,每一位可以表示2个数: 0或1.byte(字节) 有8位,可以表示的数为2的8次方,即256个数,范围为[0-255]. ...
- 对ssm框架里面的一些常用注解的理解
@Componcnt :作用就是把当前类对象存入spring容器中 属性:value 用于指定bean的id 当我们不写的时候默认就是当前类名,并且首字母要小写 ------------------- ...
- ffmpeg开发文档
libavcodec - 编码解码器 libavdevice - 输入输出设备的支持 libavfilter - 视音频滤镜支持 libavformat - 视音频等格式的解析 libavutil - ...
- Eclipse集成Git做团队开发
在日常开发工作中,我们通常使用版本控制软件管理团队的源代码,常用的SVN.Git.与SVN相比,Git有分支的概念,可以从主分支创建开发分支,在开发分支测试没有问题之后,再合并到主分支上去,从而避免了 ...
- github上好用的非代码工具
1. github上好用的非代码工具 1.1. 面试题地址 地址 1.2. 书籍 这里 1.3. 百度网盘不限速下载器 这里
- httpPost请求用java代码实现的方法
原文:https://www.cnblogs.com/johnson-yuan/p/6713384.html package com.day3.sample; //首先下面我我们需要导入的jar包和文 ...
- es聚合后排序
注意: es版本至少6.1以上 语句: GET 76/sessions/_search { "size": 0, "query": { "bool&q ...
- 整合Spring+Hibernate+Struts2的时候发现json数据一直无法传到页面,提示no-Session
执行了ajax,页面没有任何反应 怀疑json没有值,想查看json中的内容,使用了ObjectMapper: ObjectMapper om=new ObjectMapper(); System.o ...