我有两个类似的功能,我想通过一个模板功能来实现:
function csrfSafeMethod(method) {
// these HTTP methods do not require CSRF protection
return (/^(GET|HEAD|OPTIONS|TRACE)$/.test(method));
}
$.ajaxSetup({
beforeSend: function(xhr, settings) {
if (!csrfSafeMethod(settings.type) && !this.crossDomain) {
xhr.setRequestHeader("X-CSRF-Token", {% csrf_token %});
}
}
});
我想创建魔术模板功能:
A& get(void);
const A& get(void) const;