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
| var shape = { | |
| type: "", | |
| getType: function () { | |
| return this.type; | |
| }, | |
| }; | |
| function Triangle(a, b, c) { | |
| this.type = "triangle"; | |
| this.a = a; |
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
| Array.prototype.shuffle = function () { | |
| let c = []; | |
| const MAX = this.length; | |
| function testAndShuffle(item) { | |
| let index = Math.floor(Math.random() * MAX); | |
| if (typeof c[index] === "undefined") { | |
| c[index] = item; | |
| } else { |
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
| function getRgb(hex) { | |
| try { | |
| if ( | |
| typeof hex !== "string" || | |
| (hex.length !== 7 && hex.length !== 4) || | |
| hex[0] !== "#" | |
| ) { | |
| throw { | |
| name: "Problem", | |
| message: "This is not a proper string", |
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
| function Person(name) { | |
| console.log("old constructor"); | |
| let obj; | |
| // Another time just return obj above | |
| Person = function Person() { | |
| console.log("new constructor"); | |
| return obj; | |
| }; |
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
| // Implementation of observable value with cb function | |
| function dandycode() { | |
| var value = Array.prototype.slice.call(arguments)[0]; | |
| var dandy = {}; | |
| if (!(this instanceof dandycode)) { | |
| return new dandycode(value); | |
| } | |
| this.value = value; |
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
| class Person { | |
| constructor(name) { | |
| this.name = name; | |
| } | |
| count() { | |
| return Person.prototype.counter++; | |
| } | |
| } | |
| Person.prototype.counter = 0; |
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
| class Humanoid { | |
| constructor(name) { | |
| this.name = name; | |
| } | |
| say() { | |
| console.log(this.name); | |
| } | |
| } | |
| class Human extends Humanoid { |
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
| function Device(power) { | |
| this.power = power; | |
| this.turnPower = function() { this.power = !this.power }; | |
| } | |
| Device.prototype.sayHello = function() { this.power ? console.log('hello, the power is on') : ''} | |
| function Computer(proccessor, memory) { | |
| this.proccessor = proccessor; | |
| this.memory = memory; |
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
| const asyncReducerFactory = (name) => { | |
| return (state = { data: null, isLoading: false, error: null }, action) => { | |
| switch (action.type) { | |
| case `FETCH_${name}_STARTED`: | |
| return { data: null, isLoading: true, error: null }; | |
| case `FETCH_${name}_SUCCESS`: | |
| return { data: action.payload, isLoading: false, error: null }; | |
| case `FETCH_${name}_ERROR`: | |
| return { data: null, isLoading: false, error: action.payload }; | |
| default: |
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
| // jasmine | |
| const customMatchers = { | |
| toBeArray: function () { | |
| return { | |
| compare: function (item) { | |
| const result = { | |
| pass: item instanceof Array, | |
| message: '' | |
| }; |
NewerOlder