// ПОЧЕМУ super.model ЗДЕСЬ undefined
class A {
constructor() {
// ...
}
method() {
// ...
}
static sMethod() {
// ...
}
}
class B extends A {
constructor(x, y) {
super(x);
super.method(y);
}
}
function A() {
if(!(this instanceof A)) {
throw new Error('Class constructor A cannot be invoked without \'new\'');
}
// ...
}
A.prototype.constructor = A;
A.prototype.method = function method() {
// ...
};
A.sMethod = function sMethod() {
// ...
};
function B(x, y) {
if(!(this instanceof B)) {
throw new Error('Class constructor B cannot be invoked without \'new\'');
}
A.call(this, x);
A.prototype.method.call(this, y);
}
B.prototype = Object.create(A.prototype);
B.prototype.constructor = B;
B.sMethod = A.sMethod; //static методы тоже наследуются
function distantion(x1, y1, x2, y2) {
return Math.sqrt(Math.pow(x2 - x1, 2) + Math.pow(y2 - y1, 2));
}
#!/bin/bash
rm $DIST_FILE
touch $DIST_FILE
for f in $(ls $SRC_DIR | grep .js)
do cat $SRC_DIR/$f >> $DIST_FILE
done
uglifyjs $DIST_FILE -cmo $DIST_FILE
SRC_DIR=$PWD/src/js DIST_FILE=$PWD/dist/script.js bash ./concat.sh
Для удобства лучше положить это в packaje.json в scripts.concat и запускать как npm run concat const url = `${location.protocol === 'http:' ? 'ws:' : 'wss:'}//${location.host}/`;
var socket;
var connected = false;
typeof WebSocket !== 'undefined' && function connect() {
socket = new WebSocket(url);
socket.onmessage = onMessage;
socket.onopen = () => connected = true;
socket.onerror = err => {
console.error(err);
socket.onclose = null;
connected = false;
socket.close();
connect();
};
socket.onclose = event => {
console.info(`WebSocket closed with code ${event.code}! ${event.reason}`);
connected = false;
if(event.wasClean) return;
connect();
};
}();
function onMessage(event) {
//...
}
var nameThatNumber = function() {
var names = {
10: 'ten',
1: 'one', 11: 'eleven',
2: 'two', 12: 'twelve', 20: 'twenty',
3: 'three', 13: 'thirteen', 30: 'thirty',
4: 'four', 14: 'fourteen', 40: 'fourty',
5: 'five', 15: 'fifteen', 50: 'fifty',
6: 'six', 16: 'sixteen', 60: 'sixty',
7: 'seven', 17: 'seventeen', 70: 'seventy',
8: 'eight', 18: 'eighteen', 80: 'eighty',
9: 'nine', 19: 'nineteen', 90: 'ninety',
100: 'hundred',
k1: 'thousand',
k2: 'million',
k3: 'billion'
};
function stringify(num) {
if(num < 1000) {
return triade(num);
}
var triades = [];
var n = num;
while(n) {
triades.push(n % 1000);
n = Math.floor(n / 1000);
}
return triades.map(function(n, i) {
var t = triade(n);
if(t === '') {
return '';
}
var nm = ' ' + (names['k' + i] || '');
return t + nm;
}).reverse().join(' ').replace(/\s+/g, ' ').trim();
}
function triade(num) {
var n = num;
if(n === 0) {
return '';
}
if(n <= 20) {
return names[n];
}
var result = '';
if(n >= 100) {
result = names[Math.floor(n / 100)] + ' ' + names[100];
}
n %= 100;
if(n === 0) {
return result;
}
if(result !== '') {
result += ' and ';
}
if(n <= 20) {
return result + names[n];
}
result += names[Math.floor(n / 10) * 10];
n %= 10;
if(n !== 0) {
result += ' ' + names[n];
}
return result;
}
return function nameThatNumber(num) {
var n = Math.abs(parseInt(num));
if(isNaN(n)) {
return 'Not a number!';
}
if(n === 0) {
return 'zero';
}
return (num < 0 ? 'minus ' : '') + stringify(n);
};
}();