所以问题很简单,如果在JavaScript中声明名为delete的方法是安全的(明智的)。示例:
var request = { delete:function(url){ //一些代码... } } request.delete('page.dev/users/1');我在Firefox中对此进行了测试并且功能正常,但只是想知道它是否会导致某些问题其它浏览器;或者一般来说,如果这是一个好习惯。
解决方案如果你使用这个['style'] ,但是使用 this.style ,你应该避免保留字,包括删除。根据规范,使用保留字作为属性名称实际上是可以的,但是无论如何我都会避免它,因为有一些不好的实现(对于使用保留字而言,无论上下文如何,它通常都会有一种糟糕的感觉)。 p>
So the question is simply, if it's safe (wise) to declare method called "delete" in JavaScript. Example:
var request = { delete : function (url) { // Some code... } } request.delete('page.dev/users/1');I've tested this in Firefox and it's functional, but just wondering if it could cause problems in some other browsers; or in general if is it a good practice.
解决方案You'll never have an issue if you use this['style'], but with this.style, you should avoid reserved words, which does includes delete. According to the spec, it's actually OK to use reserved words as property names, but I would avoid it anyway because there are some bad implementations around (also it just has a generally bad feel to use reserved words, whatever the context).
更多推荐
在JavaScript中声明删除方法是否安全
发布评论