我有这个"课程":
function FindArrayObject(arr, property, value) {
var $this = this;
[ some code here ]
return $this;
}
FindArrayObject.prototype.index = function() {
return this.result;
};
FindArrayObject.prototype.element = function() {
return ( this.result === -1 ? false : 'Something else' );
};
但是我想将它附加到Array原型,所以我不需要用new FindArrayObject
初始化它并传递数组。
一个大问题是this
会引用数组而不是类,所以我不知道我们是否可以,也会导致" sub"没有this
的函数无法检索值,但我会尝试询问。
谢谢!
答案 0 :(得分:1)
您可以使用public void CreateEnterpriseProjectType(Guid eptGuid, string eptName, string eptDescription)
{
ProjectContext pwaContext = new ProjectContext(this.PWA_URL);
EnterpriseProjectTypeCreationInformation eptData = new EnterpriseProjectTypeCreationInformation();
eptData.Id = eptGuid;
eptData.Name = eptName;
eptData.Description = eptDescription;
eptData.IsDefault = false;
eptData.IsManaged = true;
eptData.WorkspaceTemplateName = "PROJECTSITE#0";
eptData.ProjectPlanTemplateId = Guid.Empty;
eptData.WorkflowAssociationId = Guid.Empty;
eptData.Order = 4;
List<ProjectDetailPageCreationInformation> projectDetailPages = new
List<ProjectDetailPageCreationInformation>() {
new ProjectDetailPageCreationInformation() {
Id = pwaContext.ProjectDetailPages[1].Id, IsCreate = true }
};
eptData.ProjectDetailPages = projectDetailPages;
pwaContext.Load(pwaContext.EnterpriseProjectTypes);
pwaContext.ExecuteQuery();
EnterpriseProjectType newEpt = pwaContext.EnterpriseProjectTypes.Add(eptData);
pwaContext.EnterpriseProjectTypes.Update();
pwaContext.ExecuteQuery();
}
。这将使该函数可用于您在脚本范围内初始化的所有数组。
答案 1 :(得分:0)
Array.prototype.FindArrayObject = function (arr,property, value) {
var $this = this;
[ some code here ]
}
您可以像这样使用
var a = new Array.prototype.FindArrayObject([],'','')