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
function getBaseClass(MaybeClass) { | |
if (typeof MaybeClass !== 'function') { | |
return null; | |
} | |
const Proto = Reflect.getPrototypeOf(MaybeClass); | |
return !Proto.name | |
? MaybeClass | |
: getBaseClass(Proto); |
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 req = new XMLHttpRequest(); | |
req.open("post", 'https://jquery.com', true); | |
req.onreadystatechange = function receiveResponse() { | |
console.log('readyState: ', this.readyState); | |
console.log('status: ', this.status); | |
console.log('response: ', this.response.length); | |
if (this.readyState == 4) { | |
if (this.status === 0 && this.response.length === 0) { | |
return console.log('NO CON') |
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 Person = { | |
init: function(name) { | |
this.name = name; | |
}, | |
doSomethingAndUseSpeak: function(text) { | |
this.speak({name: this.name, text}) | |
} | |
}; | |
var canSpeak = { |
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
// 9: object-literals - basics | |
// To do: make all tests pass, leave the assert lines unchanged! | |
describe('The object literal allows for new shorthands', () => { | |
const x = 1; | |
const y = 2; | |
describe('with variables', () => { | |
it('the short version for `{x: x}` is {x}', () => { |
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
That looks great. Sorry it took me forever to take a look at it. | |
One pedantic thing that I would change is that I would aim for immutability whenever possible. | |
For example, ApplicationScope.setArgs (https://github.com/mdix/diy-di-typescript/blob/master/class/ApplicationScope.ts#L4) | |
wouldn't be necessary if instead the ApplicationScope took the args in the constructor. | |
That way, you are guaranteed that everything is initialized correctly throughout the entire program. | |
Another pedantic thing I would watch out for is to purge your scope class of any logic. | |
That includes array access, (https://github.com/mdix/diy-di-typescript/blob/master/class/Injector.ts#L17). | |
Even though "getArgs()[0]" looks harmless, it's the beginning of an ArgumentParser class, and so that's where that logic usually belongs. | |
Otherwise, more and more logic will creep in to your scope object.None of that logic will be testable. | |
On the other hand, keeping the logic in an ArgumentParser class means you can test the corner cases, such 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
'use strict'; | |
var stampit = require('stampit'); | |
var myStamp = | |
stampit(). | |
init(() => { | |
var privateMethod = () => { | |
console.log('YAY'); | |
} |
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
myStamp = | |
stampit(). | |
init(() => { | |
this.privateMethod = () => { | |
// private method | |
} | |
}) | |
.methods({ | |
publicMethod: () => { | |
// consume privateMethod here |
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
'use strict'; | |
var stampit = require('stampit'); | |
const MyInterfaceCheckStamp = | |
stampit() | |
.init(function(stamp) { | |
for (var method in stamp.stamp.fixed.methods) { | |
var currentMethod = stamp.stamp.fixed.methods[method]; |
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
stampit() | |
.init(function() { | |
if (this.connect.toString().indexOf('not implemented') !== -1) { | |
this.connect(); | |
} | |
if (this.save.toString().indexOf('not implemented') !== -1) { | |
this.save(); | |
} | |
}) | |
.methods( |
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
'use strict'; | |
const stampit = require('stampit'); | |
var Wheels = | |
stampit() | |
.props( | |
{ | |
amount: 4, | |
diameter_inch: 17, | |
pressure_psi: 2.1 |
NewerOlder