Skip to content

Instantly share code, notes, and snippets.

@otakustay
Last active August 29, 2015 14:05
Show Gist options
  • Save otakustay/6c5d25c1ef1083b26f33 to your computer and use it in GitHub Desktop.
Save otakustay/6c5d25c1ef1083b26f33 to your computer and use it in GitHub Desktop.
private property solution
define(function (require) {
// 参考http://wiki.ecmascript.org/doku.php?id=harmony:private_name_objects
// 在不支持private names的现在,使用字符串来表示,日后能很方便地切换成private names
var names = {
handleSubmit: '_handleSubmit',
doValidate: '_doValidate'
};
var exports = {};
exports[names.handleSubmit] = function () {
// ...
this[names.doValidate]();
};
// 公有和保护方法不变
exports.validate = function () {};
});
@Exodia
Copy link

Exodia commented Aug 26, 2014

最后是要这样吧。感觉有点烦
exports[name.handleSubmit] = function () {
// ...
thisname.doValidate;
};

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment