我试图将包含大约480行的整个原型文件转换为jQuery。 我们不使用原型库。
我得到了转换convert online的内容 但它似乎只适用于少数人。但他提供了很多提示。
我怀疑是如何开始的? 当我在stackoverflow中浏览时,我得到了这么多...... 如果我们完全从原型变为jquery,我们需要使用“原型”这个词。 ? 例如:prototype to jquery - stackoverflow
var buildAShop = Class.create();
buildAShop.prototype = {
initialize: function (parameters) {
var params = parameters.evalJSON(); // passing json object so we can add more variables from jsp if needed.
this.scheduleSearchAjax = null; // keep track of the latest scheduleSearch ajax call to ensure only the last one gets displayed.
this.intrastitialContent = null; // store the intrastial content from the page so all HTML is in the jsp page.
// create controller object for all shops and their info
this.shopObj = {currentShop: params.selectedShopNumber,
shopNumbers: params.shopNumbers,
shopNumbersForSelectedSlices: params.shopNumbersForSelectedSlices};
for (var i = 0; i < params.shopNumbers.length; i++) {
var thisShopDiv = $(params.shopNumbers[i].toString());
var thisShopHeader = thisShopDiv.getFirstElementByClassName('shopHeader');
// observe the shop header for changing shops and highlighting the 'tab'
Event.observe(thisShopHeader, 'click', this.switchShop.bindAsEventListener(this, params.shopNumbers[i]));
Event.observe(thisShopHeader, 'mouseover', this.hoverHeader.bindAsEventListener(this, thisShopHeader, 'on'));
Event.observe(thisShopHeader, 'mouseout', this.hoverHeader.bindAsEventListener(this, thisShopHeader, 'off'));
// initialize this shopSet
this.initShopSet(thisShopDiv, params.shopNumbers[i], params.shopNames[i]);
};
},
// initializes a shop set
initShopSet: function (thisShopDiv, shopId, shopName) {
this.shopObj[shopId] = {};
var flt = this.shopObj[shopId];
我没有在这里给出完整的代码。
答案 0 :(得分:0)
PrototypeJS中的Class.create()
方法允许您轻松构建Javascript对象,就像使用普通OOP语言(Java,PHP等)构建一样
然而jQuery核心与Class.create()
没有直接关联,因此您需要使用本机Javascript原型构建Javascript对象。