Javascript 数据可以使用破折号访问camel大小写键

Javascript 数据可以使用破折号访问camel大小写键,javascript,jquery,Javascript,Jquery,有人能解释为什么这样做吗: $('someId')。数据('typeId',2); $('#someId')。数据('type-id');//将返回2 小提琴也在这里: 谢谢大家! 检查这个 读取-对于后跟ASCII小写字母a到z的任何破折号(U+002D),破折号将被删除,字母将转换为大写对应字母-这是因为规范这么说 The custom data attributes is transformed to a key for the DOMStringMap entry with the fo

有人能解释为什么这样做吗:

$('someId')。数据('typeId',2);
$('#someId')。数据('type-id');//将返回2

小提琴也在这里:

谢谢大家!

检查这个

读取-
对于后跟ASCII小写字母a到z的任何破折号(U+002D),破折号将被删除,字母将转换为大写对应字母-这是因为规范这么说
The custom data attributes is transformed to a key for the DOMStringMap entry with the following rules:

    any dash (U+002D) is removed;
    any letter following a dash (U+002D), before its removal, is set in its uppercase counterpart.