0
我將在PHP中編寫一個解析器,它將把jqplot庫轉換爲它的php等效的OOP映射。目標是允許從PHP的jqplot配置(當然使用js庫)如何將JavaScript類映射到一個php類?
你可以推薦一個更好的方式來解析這個js代碼,然後使用正則表達式嗎?
示例代碼
/**
* Class: Axis
* An individual axis object. Cannot be instantiated directly, but created
* by the Plot oject. Axis properties can be set or overriden by the
* options passed in from the user.
*
*/
function Axis(name) {
$.jqplot.ElemContainer.call(this);
// Group: Properties
//
// Axes options are specified within an axes object at the top level of the
// plot options like so:
// > {
// > axes: {
// > xaxis: {min: 5},
// > yaxis: {min: 2, max: 8, numberTicks:4},
// > x2axis: {pad: 1.5},
// > y2axis: {ticks:[22, 44, 66, 88]}
// > }
// > }
// There are 4 axes, 'xaxis', 'yaxis', 'x2axis', 'y2axis'. Any or all of
// which may be specified.
this.name = name;
this._series = [];
// prop: show
// Wether to display the axis on the graph.
this.show = false;
// prop: tickRenderer
// A class of a rendering engine for creating the ticks labels displayed on the plot,
// See .
this.tickRenderer = $.jqplot.AxisTickRenderer;
// prop: tickOptions
// Options that will be passed to the tickRenderer, see options.
this.tickOptions = {};
// prop: labelRenderer
// A class of a rendering engine for creating an axis label.
this.labelRenderer = $.jqplot.AxisLabelRenderer;
// prop: labelOptions
// Options passed to the label renderer.
this.labelOptions = {};
// prop: label
// Label for the axis
this.label = null;
// prop: showLabel
// true to show the axis label.
this.showLabel = true;
Javascript沒有課程。用正則表達式解析代碼是一個可怕的想法。 – 2011-04-05 11:55:30