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 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
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 initialized = false, | |
user = { | |
'data': [ | |
{} | |
] | |
}, | |
dataUrl = '', | |
updateUrl = '', | |
requests = []; |
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
define(['lib/validator/rule.notEmpty'], function(_ruleNotEmpty_) { | |
describe('rule.notEmpty', function() { | |
var ruleNotEmpty; | |
beforeEach(function() { | |
ruleNotEmpty = new _ruleNotEmpty_(); | |
}); | |
describe('its checkField function', function() { | |
// just wrap an it in a loop (if you have jquery you can use each) |
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
/* globals module*/ | |
module.exports = function(grunt) { | |
grunt.initConfig({ | |
dalek: { | |
chrome: { | |
options: { | |
browser: ['chrome'] | |
}, | |
src: 'src/spec/**/*chrome*.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
db.user.findOne({'userid': '1'}, function(err, doc) { | |
db.user.update({'_id': doc._id}, {$set: {'mails.0.isRead': 'true'}}, function(err2, doc2) { | |
// doc2 is true / false | |
// doc has a reference to the document (so it will show the update) | |
}); | |
}); | |
db.user.findAndModify( | |
{ | |
'query': {'userid': '1'}, |
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 one = function() { | |
}; | |
var two = function() { | |
}; |
NewerOlder