made with esnextbin
Created
May 4, 2016 20:08
-
-
Save mauriciopoppe/ff5fc627922285b3d085bd9c42420736 to your computer and use it in GitHub Desktop.
esnextbin sketch
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!doctype html> | |
<html> | |
<head> | |
<meta charset="utf-8"> | |
<title>ESNextbin Sketch</title> | |
<!-- put additional styles and scripts here --> | |
</head> | |
<body> | |
<!-- put markup and other contents here --> | |
</body> | |
</html> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import React, {Component} from 'react' | |
class AbstractClass extends Component { | |
constructor() { | |
super() | |
if (this.constructor === AbstractClass) { | |
throw Error('Instantiation of abstract class AbstractMyClass is not allowed') | |
} | |
} | |
getSuperName () { | |
var proto = this.constructor.prototype | |
return Object.getPrototypeOf(proto).constructor.name | |
} | |
} | |
class A extends AbstractClass {} | |
class B extends A {} | |
console.log(new A()) // works | |
console.log(new A().getSuperName()) // AbstractMyClass | |
console.log(new B().getSuperName()) // A | |
console.log(new AbstractMyClass()) // throws error |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"name": "esnextbin-sketch", | |
"version": "0.0.0", | |
"dependencies": { | |
"react": "15.0.1", | |
"babel-runtime": "6.6.1" | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
'use strict'; | |
var _getPrototypeOf = require('babel-runtime/core-js/object/get-prototype-of'); | |
var _getPrototypeOf2 = _interopRequireDefault(_getPrototypeOf); | |
var _classCallCheck2 = require('babel-runtime/helpers/classCallCheck'); | |
var _classCallCheck3 = _interopRequireDefault(_classCallCheck2); | |
var _createClass2 = require('babel-runtime/helpers/createClass'); | |
var _createClass3 = _interopRequireDefault(_createClass2); | |
var _possibleConstructorReturn2 = require('babel-runtime/helpers/possibleConstructorReturn'); | |
var _possibleConstructorReturn3 = _interopRequireDefault(_possibleConstructorReturn2); | |
var _inherits2 = require('babel-runtime/helpers/inherits'); | |
var _inherits3 = _interopRequireDefault(_inherits2); | |
var _react = require('react'); | |
var _react2 = _interopRequireDefault(_react); | |
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } | |
var AbstractClass = (function (_Component) { | |
(0, _inherits3.default)(AbstractClass, _Component); | |
function AbstractClass() { | |
(0, _classCallCheck3.default)(this, AbstractClass); | |
var _this = (0, _possibleConstructorReturn3.default)(this, (0, _getPrototypeOf2.default)(AbstractClass).call(this)); | |
if (_this.constructor === AbstractClass) { | |
throw Error('Instantiation of abstract class AbstractMyClass is not allowed'); | |
} | |
return _this; | |
} | |
(0, _createClass3.default)(AbstractClass, [{ | |
key: 'getSuperName', | |
value: function getSuperName() { | |
var proto = this.constructor.prototype; | |
return (0, _getPrototypeOf2.default)(proto).constructor.name; | |
} | |
}]); | |
return AbstractClass; | |
})(_react.Component); | |
var A = (function (_AbstractClass) { | |
(0, _inherits3.default)(A, _AbstractClass); | |
function A() { | |
(0, _classCallCheck3.default)(this, A); | |
return (0, _possibleConstructorReturn3.default)(this, (0, _getPrototypeOf2.default)(A).apply(this, arguments)); | |
} | |
return A; | |
})(AbstractClass); | |
var B = (function (_A) { | |
(0, _inherits3.default)(B, _A); | |
function B() { | |
(0, _classCallCheck3.default)(this, B); | |
return (0, _possibleConstructorReturn3.default)(this, (0, _getPrototypeOf2.default)(B).apply(this, arguments)); | |
} | |
return B; | |
})(A); | |
console.log(new A()); // works | |
console.log(new A().getSuperName()); // AbstractMyClass | |
console.log(new B().getSuperName()); // A | |
console.log(new AbstractMyClass()); // throws error |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment