Skip to content

Instantly share code, notes, and snippets.

// 1. Call superclass constructor in the constructor of a child class with this of the child class:
//var A = function(){} - our superclass
var B = function(){A.call(this);}
// 2. Create a new object based on superclass prototype and assign it to the prototype of a child class:
B.prototype = Object.create(A.prototype);
// 3. Rewrite child class constructor:
B.prototype.constructor = B;
//Let's check it:
b instanceof B // true
b instanceof A // true
var A = function() {
this.a = [];
}
A.prototype.hello = function() {
console.log('Hello from A!');
}
var B = function(a) {
if (a) {
this.a = a;
b.a = 25;
console.log(b.a) // 25
delete b.a // true
console.log(b.a) // 10
var b = new B()
b instanceof A //true
b instanceof B //true
var A = function() {
this.a = 10;
}
A.prototype.hello = function() {
console.log('Hello from A!');
}
var B = function() {
}
<!DOCTYPE html>
<html>
<head>
<asset:javascript src="asset-pipeline.js"/>
</head>
<body>
<div>
<span>Current time is:</span>
</div>
<!DOCTYPE html>
<html>
<head>
<asset:javascript src="asset-pipeline.js"/>
</head>
<body>
<div>
<span>Current time is:</span>
</div>
<div id="app"></div>
@MagicControl
MagicControl / test-component.jsx
Last active January 31, 2017 14:52
simple react component
class TestComponent extends React.Component {
constructor() {
super();
this.state = {date: new Date()};
}
componentDidMount() {
this.timerID = setInterval(
() => this.tick(),
1000
@MagicControl
MagicControl / asset-pipeline.js
Last active January 31, 2017 14:53
including react
//= require react/react.min.js
//= require react/react-dom.min.js
@MagicControl
MagicControl / build.gradle
Last active January 31, 2017 14:53
jsx-asset-pipeline config
assets {
minifyJs = true
minifyCss = true
enableSourceMaps = true
minifyOptions = [
languageMode : 'ES6',
targetLanguage: 'ES5'
]
}