ecmascript-6

How to import ES6 modules in content script for Chrome Extension

做~自己de王妃 提交于 2021-02-20 10:01:25
问题 In Chrome 61 , support for modules in JavaScript was added. Right now I am running Chrome 63. I am trying to use import / export syntax in Chrome extension content script to use modules. In manifest.json : "content_scripts": [ { "js": [ "content.js" ], } ] In my-script.js (same directory as content.js ): 'use strict'; const injectFunction = () => window.alert('hello world'); export default injectFunction; In content.js : 'use strict'; import injectFunction from './my-script.js';

How to import ES6 modules in content script for Chrome Extension

≯℡__Kan透↙ 提交于 2021-02-20 10:01:02
问题 In Chrome 61 , support for modules in JavaScript was added. Right now I am running Chrome 63. I am trying to use import / export syntax in Chrome extension content script to use modules. In manifest.json : "content_scripts": [ { "js": [ "content.js" ], } ] In my-script.js (same directory as content.js ): 'use strict'; const injectFunction = () => window.alert('hello world'); export default injectFunction; In content.js : 'use strict'; import injectFunction from './my-script.js';

Get superclass name in ES6

耗尽温柔 提交于 2021-02-20 05:40:28
问题 I have a class, and another class that extends that class. class Shape { constructor() { return this; } } class Circle extends Shape { constructor() { super(); return this; } } let foo = new Circle(); I can get foo's class with let className = foo.constructor.name // returns string 'Circle' Is it possible to get the name of foo's superclass ('Shape') in a similar manner? 回答1: Object.getPrototypeOf(Object.getPrototypeOf(foo)).constructor.name; 回答2: Got it: let superClassName = foo.__proto__._

Are ES6 classes the same as constructor functions?

此生再无相见时 提交于 2021-02-19 08:46:10
问题 As I understand it: ES6 classes are basically constructor functions, right? Of course with the benefit of not having to write stuff like this: myFunction.prototype.myInheritablemethod= "someMethod"; Is this correct? I'm asking because I'm aware there is the module pattern and the revealing module pattern, but those are not what ES6 classes are about, right? 回答1: Classes were introduced to provide syntactic sugar around the existing prototypal inheritance model of JavaScript. The following...

How filter array of objects by another array of objects [ES6]

爱⌒轻易说出口 提交于 2021-02-19 04:23:33
问题 I need to filter array of object by another array of object without knowledge of exact properties in criterias array. Let's take a look to example for better understanding. Here is an array that I need to filter const dataset = [ { id: "4", someval1: "10", someval2: "20", someval3: "30", someval4: "40" }, { id: "10", someval1: "10", someval2: "20", someval3: "30", someval4: "40" }, { id: "22", someval1: "102", someval2: "202", someval3: "302", someval4: "40" }]; Here is an array which has

How filter array of objects by another array of objects [ES6]

只愿长相守 提交于 2021-02-19 04:22:34
问题 I need to filter array of object by another array of object without knowledge of exact properties in criterias array. Let's take a look to example for better understanding. Here is an array that I need to filter const dataset = [ { id: "4", someval1: "10", someval2: "20", someval3: "30", someval4: "40" }, { id: "10", someval1: "10", someval2: "20", someval3: "30", someval4: "40" }, { id: "22", someval1: "102", someval2: "202", someval3: "302", someval4: "40" }]; Here is an array which has

JS Proxying HTML5 canvas context

一世执手 提交于 2021-02-19 02:46:11
问题 I'm hoping to proxy the canvas API so I can test that abstracted methods do actually draw to the canvas, however I'm hitting issues where after proxing I get an error: 'strokeStyle' setter called on an object that does not implement interface CanvasRenderingContext2D This code is simplified but throws the same error: /** !NB: This snippet will probably only run in Firefox */ var canvas = document.createElement("canvas"); canvas.width = 100; canvas.height = 100; canvas.style.backgroundColor =

ES6 default and named exports

丶灬走出姿态 提交于 2021-02-18 22:41:25
问题 I am trying to understand named and default exports. I have a seemingly basic requirement which I don't understand how to setup. I want to be able to import both: //app.js import Mod from './my-module' import { funcA, funcB } from './my-module' console.log('A', Mod.funcA(), funcA()); // A a a console.log('B', Mod.funcB(), funcB()); // A a a When I try, the closest way of doing this I get to is the following: //my-module.js export function funcA() { return 'a'; }; export function funcB() {

ES6 default and named exports

时光总嘲笑我的痴心妄想 提交于 2021-02-18 22:39:36
问题 I am trying to understand named and default exports. I have a seemingly basic requirement which I don't understand how to setup. I want to be able to import both: //app.js import Mod from './my-module' import { funcA, funcB } from './my-module' console.log('A', Mod.funcA(), funcA()); // A a a console.log('B', Mod.funcB(), funcB()); // A a a When I try, the closest way of doing this I get to is the following: //my-module.js export function funcA() { return 'a'; }; export function funcB() {

ES6 JavaScript template literals - What they can and can't do

ⅰ亾dé卋堺 提交于 2021-02-18 19:00:38
问题 Template literals make string manipulation much easier. However: What can and what can't they do in comparison to template libraries such as mustache and handlebars? I found it difficult to find an answer to these questions: Can they handle conditions? Can they handle loops? Can they handle functions? 回答1: The name is a bit ambiguous, but template literals do not replace template engines. They role is only to provide a more convenient syntax to work with strings. In fact, the objective was to