Skip to content

Instantly share code, notes, and snippets.

@A-gambit
Created March 16, 2015 20:08
Show Gist options
  • Select an option

  • Save A-gambit/e7e9e15325c3947238e2 to your computer and use it in GitHub Desktop.

Select an option

Save A-gambit/e7e9e15325c3947238e2 to your computer and use it in GitHub Desktop.
// твоя задача написать require
//сейчас ту? да :)
// browser.js
// nodejs
var require = {
data: [],
import: function(path){
var res = this.data.filter(function(item){
return item.path == path
});
return res[0].value
},
export: function(path, value){
this.data.push({path: path, value: value})
}
}
// a.js
(function(){
var a = require.import('b')
a()
})()
// b.js
(function(){
var b = function () {
return console.log('b')
}
, path = "b"
require.export(path, b)
})()
//ну мы же не експортим б что бы его рекваерить как я его вызову там же нет к примеру или что то в этому духе
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment