I want to use item.create()
in projectModule
, testCase
and businessFunction. because it's same prototype as item
's I copied the item
's to other functions. But i want have a one unique variable for these three functions which is called itemType
. I tried this. But an exception is occurred. How can I place a unique variable for these three functions without overriding them?
Exception:
projectModule.create.prototype.itemType = 'module';
TypeError: Cannot read property 'prototype' of undefined
JavaScript Code
var item = function () {};
item.prototype.create = function (projectName, itemName) {
console.log(projectName);
console.log(itemName);
console.log(itemType);
};
/**
* create module
*/
var projectModule = function () {};
projectModule.prototype = Object.create(item.prototype);
projectModule.create.prototype.itemType = 'module';
/**
* create tc
*/
var testCase = function () {};
testCase.prototype = Object.create(item.prototype);
testCase.create.prototype.itemType = 'tc';
/**
* create bc
*/
var businessComponent = function () {};
businessComponent.prototype = Object.create(item.prototype);
businessComponent.create.prototype.itemType = 'bc';