mirror of
https://github.com/Hopiu/angular.js.git
synced 2026-03-29 20:40:29 +00:00
fix(injector) .instantiate([Type]) produced wrong result
This commit is contained in:
parent
776739299b
commit
eb92735c9e
2 changed files with 10 additions and 1 deletions
|
|
@ -433,7 +433,7 @@ function createInjector(modulesToLoad) {
|
|||
var Constructor = function() {},
|
||||
instance, returnedValue;
|
||||
|
||||
Constructor.prototype = Type.prototype;
|
||||
Constructor.prototype = (isArray(Type) ? Type[Type.length - 1] : Type).prototype;
|
||||
instance = new Constructor();
|
||||
returnedValue = invoke(Type, instance, locals);
|
||||
|
||||
|
|
|
|||
|
|
@ -605,6 +605,15 @@ describe('injector', function() {
|
|||
});
|
||||
|
||||
|
||||
it('should instantiate object and preserve constructor property and be instanceof', function() {
|
||||
var t = $injector.instantiate(['book', 'author', Type]);
|
||||
expect(t.book).toEqual('moby');
|
||||
expect(t.author).toEqual('melville');
|
||||
expect(t.title()).toEqual('melville: moby');
|
||||
expect(t instanceof Type).toBe(true);
|
||||
});
|
||||
|
||||
|
||||
it('should allow constructor to return different object', function() {
|
||||
var obj = {};
|
||||
var Class = function() {
|
||||
|
|
|
|||
Loading…
Reference in a new issue