// ПОЧЕМУ 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) {
//...
}