This file contains 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
// 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 |
This file contains 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
var A = function() { | |
this.a = []; | |
} | |
A.prototype.hello = function() { | |
console.log('Hello from A!'); | |
} | |
var B = function(a) { | |
if (a) { | |
this.a = a; |
This file contains 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
b.a = 25; | |
console.log(b.a) // 25 | |
delete b.a // true | |
console.log(b.a) // 10 |
This file contains 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
var b = new B() | |
b instanceof A //true | |
b instanceof B //true |
This file contains 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
var A = function() { | |
this.a = 10; | |
} | |
A.prototype.hello = function() { | |
console.log('Hello from A!'); | |
} | |
var B = function() { | |
} |
This file contains 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> | |
<asset:javascript src="asset-pipeline.js"/> | |
</head> | |
<body> | |
<div> | |
<span>Current time is:</span> | |
</div> |
This file contains 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> | |
<asset:javascript src="asset-pipeline.js"/> | |
</head> | |
<body> | |
<div> | |
<span>Current time is:</span> | |
</div> | |
<div id="app"></div> |
This file contains 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
class TestComponent extends React.Component { | |
constructor() { | |
super(); | |
this.state = {date: new Date()}; | |
} | |
componentDidMount() { | |
this.timerID = setInterval( | |
() => this.tick(), | |
1000 |
This file contains 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
//= require react/react.min.js | |
//= require react/react-dom.min.js |
This file contains 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
assets { | |
minifyJs = true | |
minifyCss = true | |
enableSourceMaps = true | |
minifyOptions = [ | |
languageMode : 'ES6', | |
targetLanguage: 'ES5' | |
] | |
} |
NewerOlder