我使用这样的自定义框架:
var SForm = $A.support({
Name: 'SForm',
// instance based
// hidden, created by using this
// static based
S: {
google: 'https://plus.google.com/_/favicon?domain=',
pre_url: /(http:)|(https:)\/\//,
domain: /:\/\/(www\.)?([\.a-zA-Z0-9\-]+)/,
// the good parts has good url regex - implement it some time
url: /:\/\/(www\.)?[\x00-\x7F]{1,1800}\.[\x00-\x7F]{1,200}/,
email: /\S{1,64}@[\x00-\x7F]{1,255}\.[\x00-\x7F]{1,255}/,
tweet: /\S{1,40}/,
title: /\S{1,32}/,
name: /\S{1,64}/,
pass: /\S{6,20}/,
empty: /\S+/
},
constructor : function (form_elements) {
$A.someKey(form_elements, function (val) {
if (val.type !== 'checkbox') {
this.form_obj[val.name] = val.value;
} else if (val.type === 'checkbox') {
this.form_obj[val.name] = val.checked;
}
}, this);
},
// ... more
这对我有用,因为我可以稍微模仿 Java 类系统。
但是我不知道如何使我的实例变量显式,就像我的静态变量一样。
这是框架:
$P.block = $P.support = $P.parsel = function (obj, config_module) {
$R.Parsel[obj.Name] = obj;
// all properties are private
if (!config_module) {
return undefined;
}
// all properties are public
if (config_module === true) {
return obj;
}
// constructor based, all properties are public
if (config_module === 'constructor') {
var object_public;
if (obj.constructor) {
object_public = obj.constructor;
delete obj.constructor;
}
$A.someKey(obj, function (val, key) {
if (/^s_/.test(key)) {
object_public[key] = val;
} else if (/^p_/.test(key)) {
object_public.prototype[key] = val;
} else {
object_public.prototype[key] = val;
}
});
return object_public;
}
};