我试图将我的一些旧javascript旧代码转换为 Revealing Prototype Pattern 。我写下面的代码,但得到错误
TypeError:AllShowing不是构造函数
$(document).ready(function () {
var allShowing = new AllShowing();
// Edit record
$('#allShowingGrid').on('click', 'a.edit_showing', function (e) {
e.preventDefault();
$('html, body').animate({ scrollTop: 0 }, 'fast');
var command = 'Edit';
var tr = $(this).closest('tr');
allShowing.mapGridDataToFormData(command, tr);
});
});
var AllShowing = function () {
this.gridContainer = "#allShowingGrid";
this.showRequestData = function() {
$("#requestData").show();
};
};
AllShowing.prototype = function () {
var mapGridDataToFormData = function(command, tr) {
if (command == 'Edit') {
showRequestData.call(this);
var id = $.trim((tr).children("td.row_id").text());
var propId = $.trim((tr).children("td.showing_PropertyId").text());
var name = $.trim((tr).children("td.showing_FirstName").text());
var email = $.trim((tr).children("td.showing_Email").text());
var phone = $.trim((tr).children("td.showing_WorkPhone").text());
var schedule = $.trim((tr).children("td.showing_PreferredDate").text());
var reqDetails = $.trim((tr).children("td.showing_Comment").text());
var startHour = $.trim((tr).children("td.showing_StartHour").text());
$("#hdVisitorId").val(id);
$("#FirstName").val(name);
$("#Email").val(email);
$("#Work_Phone").val(phone);
$("#PreferredDate").val(schedule);
$("#StartHour").val(startHour);
}
};
return {
mapGridDataToFormData: mapGridDataToFormData
};
}();
我会检查一些类似的帖子,例如Javascript: TypeError: … is not a constructor和Javascript “Not a Constructor” Exception while creating objects
但无法解决我的错误。在我犯错的地方,任何人都可以帮助我。
答案 0 :(得分:0)
更改var AllShowing = function () {
到
function AllShowing() {
它应该有用