[Javascript] MetaProgramming: new.target
new.target is a new “magical” value available in all functions, thoughin normal functions it will always be undefined. In any constructor,new.target always points at the constructor that new actuallydirectly invoked.
class Parent {
constructor() {
if (new.target === Parent) {
console.log( "Parent instantiated" );
}
else {
console.log( "A child instantiated" );
}
}
}
class Child extends Parent {}
var a = new Parent();
// Parent instantiated
var b = new Child(); // here new.target is undefined
// A child instantiated
When the class is extended, it will show undefined in the parent class construcotr().
[Javascript] MetaProgramming: new.target的更多相关文章
- [Javascript] MetaProgramming: function name
Each function should have a 'name' property. It can be anonymous, empty, the same as function name, ...
- 聊Javascript中的AOP编程
Duck punch 我们先不谈AOP编程,先从duck punch编程谈起. 如果你去wikipedia中查找duck punch,你查阅到的应该是monkey patch这个词条.根据解释,Mon ...
- 聊聊Javascript中的AOP编程
Duck punch 我们先不谈AOP编程,先从duck punch编程谈起. 如果你去wikipedia中查找duck punch,你查阅到的应该是monkey patch这个词条.根据解释,Mon ...
- 读javascript高级程序设计17-在线检测,cookie,子cookie
一.在线状态检测 开发离线应用时,往往在离线状态时把数据存在本地,而在联机状态时再把数据发送到服务器.html5提供了检测在线状态的方法:navigator.onLine和online/offline ...
- 超链接的#和javascript:void(0)的区别
转载于:http://www.uw3c.com/cssviews/css12.html 在工作中,如果我们想把a标签中的链接置成空链接,我们一般会用两种方法: 1 <a href=" ...
- javascript AOP实现
参考:http://www.cnblogs.com/rubylouvre/archive/2009/08/08/1541578.html function Person(){ this.say = f ...
- JavaScript操作DOM的那些坑
js在操作DOM中存在着许多跨浏览器方面的坑,本文花了我将近一周的时间整理,我将根据实例整理那些大大小小的“坑”. DOM的工作模式是:先加载文档的静态内容.再以动态方式对它们进行刷新,动态刷新不影响 ...
- javascript: 常用操作
1,取得输入框的输入值,修改输入框的输入值 根据id获取id的值 jquery代码: $('#version_number').val(); 解释:$是jQuery的标准用法,('#version_n ...
- JavaScript打开新窗口被拦截问题
新窗口打开页面,一个很常用的效果,至于代码,一般第一反应都是这么写: window.open(url); 但是主流的浏览器都会拦截这种效果(可能这些年弹窗广告太多,如果浏览器不拦截,用户受不了) ...
随机推荐
- avalon中require的实现
var plugins = { loader: function(builtin) { window.define = builtin ? innerRequire.define : otherDef ...
- sublime搭建c++/java/lua/python/ruby的配置文件
本人电脑win7 64位 提前装一下convert to utf-8插件,编译运行出现乱码,组合键ctrl+shift+c把源文件转成gbk编码. 仍乱码的话,重启编辑器|电脑|重新编辑中文部分. c ...
- 排名第一、第二的OCR软件
排名第一.第二的OCR软件 第一:ABBYY FineReader OCR世界排名第一,在俄罗斯获国际科技大奖奖超过卡巴斯基! 不仅仅只是文字识别,还能表格识别,版面还原,字体识别,文档结构 ...
- 图表插件——Highcharts插件的使用(一柱状图)
1.下载Highcharts插件 官方下载网址:http://www.highcharts.com/download 2.引入需要的js文件 <script src="~/Script ...
- uva 1400 - "Ray, Pass me the dishes!"
又是一道线段树区间更新的题: #include<cstdio> #include<algorithm> #include<cstring> #define ll l ...
- ANDROID_MARS学习笔记_S04_001_OAUTH获取request_token
一.代码 1.xml(1)main.xml <?xml version="1.0" encoding="utf-8"?> <LinearLay ...
- 如何让windows版Safari支持H5 audio/video?
今天在windows版Safari上看效果的时候惊奇地发现它竟然不支持HTML5的audio/video, 这样的话就无法复现不少ios上出现的问题. 在同事提醒下, 发现Safari HTML5 A ...
- 【HDOJ】1978 How many ways
DFS. #include <stdio.h> #include <string.h> #define MAXNUM 105 int map[MAXNUM][MAXNUM], ...
- ArrayList集合排序
using System;using System.Collections;using System.Collections.Generic;using System.Text; namespace ...
- ASP.NET中验证控件的使用
转自:http://www.cnblogs.com/yangmingming/archive/2010/03/09/1682006.html 前言: 前几日,无奈用JS判断控件的有效性,发现的确是一件 ...