ssnau / injecting Goto Github PK
View Code? Open in Web Editor NEWdependency injection for javascript. no magical decorators.
dependency injection for javascript. no magical decorators.
你好,我需要多次注册一个 name。如果其对应为service,并且如果已经调用了invoke,即使设置了overwritable,依然会报错,想请教下,这种情况应该怎么来处理?如果是service的话,之前的name不能再被覆盖了吗?下面是测试代码:
//story.js
module.exports = function(place, person){
return {
place: place,
person: person.name,
pet: person.pet.name
};
};
// index.js
var injecting = require('injecting');
var app = injecting();
app.register('place', 'pacific');
app.register('cat', function() {
this.name = "white cat";
});
app.register('person', function(cat) {
this.name = "robot";
this.pet = cat;
});
let story = require('./story');
app.register('story', story, {
overwritable: true
});
app.invoke(function(story){
console.log(story);
});
app.register('story', story);
app.invoke(function(story){
console.log(story);
});
@ssnau
get-parameter-names.js 中获取参数名有点小问题,如题;
result = [code.slice(0, arrowIndex).trim()];
改为
var arrowParams = code.slice(0, arrowIndex).trim();
result = [arrowParams.indexOf(' ') === -1 ? arrowParams : arrowParams.split(' ')[1]];
即可修复,或者其他更优雅的实现
First of all thank you for the nice di.
Let us take the code from the README example
var injecting = require('injecting');
var app = injecting();
app.register('name', 'jack');
app.register('person', function(name) {
this.name = name;
});
app.invoke(function(person) {
console.log(person.name); // jack
});
after minification it will be something like this
var injecting = require("injecting"),
app = injecting();
app.register("name","jack");
app.register("person",function(n){this.name=n});
app.invoke(function(n){console.log(n.name)});
The code above will throw an error UnhandledPromiseRejectionWarning: Unhandled promise rejection (rejection id: 1): Error: n is not found!
, because the function property name
was replaced with n
after minification.
So the question is: is there any workaround to deal with minification?
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.