Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/416.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/angularjs/20.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 服务之间的AngularJS继承_Javascript_Angularjs - Fatal编程技术网

Javascript 服务之间的AngularJS继承

Javascript 服务之间的AngularJS继承,javascript,angularjs,Javascript,Angularjs,我对角度世界还很陌生,遇到了一个问题,我想实现一个接口(isch)行为 我有一个“核心”工厂,它是我的领域的一部分,看起来如下所示: (function() { 'use strict'; var domainModel = angular.module('my.model'); domainModel.factory('IVehicle', function(Timezone) { function IVehicle(DTO) {

我对角度世界还很陌生,遇到了一个问题,我想实现一个接口(isch)行为

我有一个“核心”工厂,它是我的领域的一部分,看起来如下所示:

(function() {
    'use strict';

    var domainModel = angular.module('my.model');
    domainModel.factory('IVehicle', function(Timezone) {
        function IVehicle(DTO) {
            this.Timezone = new Timezone();
            this.DTO = DTO;
            this.engine = DTO.engine;
            this.descriptor = this.getDescriptor();
        }

        IVehcile.prototype.getDescriptor = function() {
            if (this.type === -1) {
                return "this is a diesel vehicle";
            }
            else if (this.type === 0) {
                return "this is a fuel vehicle";
            }
            else {
                return "this is a environment vehicle";
            }
        };

        IVehicle.prototype.isGenericActivity = function() {
            return true;
        };

        return IVehicle;
    });
})();
现在我有了一个子模块,它“继承”了这个工厂:

(function() {
    "use strict";

var models = angular.module('my.model');

models.factory('Car', function(Timezone, IVehicle) {
    function Car(CarDTO) {
        var me = this;



        IVehicle.call(me, CarDTO);

        this.additionalAttribute = CarDTO.additionalAttribute

        Car.prototype.hasParameters = function() {
        return this.parameters !== undefined && this.parameters.length !== 0;
    };

        Car.prototype = Object.create(ICar.prototype);

        Car.prototype.getDescriptor = function() {
        if (this.type === -1) {
            return "this is a diesel car";
        }
        else if (this.type === 0) {
            return "this is a fuel car";
        }
        else {
            return "this is a environment car";
        }
        };

        Car.prototype.isGenericActivity = function() {
            return true;
        };
}
    return Car;
    });
})();
当我运行这个时,我在IVehile中的this.descriptor=this.getDescriptor()上得到一个错误,因为Car不知道这个.getDescriptor()。字段(this.DTO、this.engine设置正确)


这是正确的方法吗?还是我可以把iVihicle写成一个真正的接口(作为一个关于它的孩子要实现什么的契约)?如果这是正确的方法,我如何处理IVehichle构造函数中的函数调用

所有
Car
原型分配都在
功能车()内
当在车外时,也不清楚什么是
ICar
,因为它从未设置过。如果您想从
ivehile
继承内容,请检查
ivehile
是否拼写错误,而不是每次拼写相同,那么调用的
ivehile
不应该是
ICar