JS中的变量名称有什么问题? [英] What's wrong with the variable name in JS?

查看:56
本文介绍了JS中的变量名称有什么问题?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

< pre class = snippet-code-js lang-js prettyprint-override> var name = ['name1','name2','name2']; console.log(name,name.length) ; // name1,name2,name2 17



并且



  var names = ['name1','name2' ,'name2']; console.log(names,names.length); //(3)[ name1, name2, name2] 3  



JS中的变量 name 有什么问题?

strong>

解决方案

window.name 获取/设置窗口的名称。

  string = window.name; 
window.name =字符串;

窗口的名称主要用于设置超链接和表单的目标。 Windows不需要具有名称。



在某些框架中,它也已用于提供跨域消息传递(例如, SessionVars 和Dojo的 dojox.io.windowName )作为JSONP的更安全替代方案。但是,托管敏感数据的现代Web应用程序不应依赖window.name进行跨域消息传递,而应使用postMessage API。


Don不要将值设置为 unstring ,因为其get方法将调用 toString 方法。



var name = ['name1', 'name2', 'name2'];
console.log(name, name.length);
// name1,name2,name2 17

AND

var names = ['name1', 'name2', 'name2'];
console.log(names, names.length);
// (3) ["name1", "name2", "name2"] 3

What's wrong with the variable name in JS?

解决方案

window.name Gets/sets the name of the window.

string = window.name;
window.name = string;

The name of the window is used primarily for setting targets for hyperlinks and forms. Windows do not need to have names.

It has also been used in some frameworks for providing cross-domain messaging (e.g., SessionVars and Dojo's dojox.io.windowName) as a more secure alternative to JSONP. Modern web applications hosting sensitive data should however not rely on window.name for cross-domain messaging but instead rather utilize the postMessage API.

Don't set the value to something unstring since its get method will call the toString method.

这篇关于JS中的变量名称有什么问题?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆