博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
JavaScript CSS助手
阅读量:2517 次
发布时间:2019-05-11

本文共 1355 字,大约阅读时间需要 4 分钟。

I spend a good amount of time looking at JavaScript framework source code. Regardless of which frameworks you have allegiance to, you can learn an awful lot by looking under the hood of widely used code collections. One of many handy snippets can be found within the MooTools source code: functions to camelize and hyphenate strings so that your own min framework can accept either form of CSS setter or getter. Here are the functions in all of their glory.

我花了大量时间研究JavaScript框架源代码。 无论您使用哪种框架,都可以通过查看广泛使用的代码集合的幕后知识来学习很多知识。 您可以在MooTools源代码中找到许多方便的摘录之一:驼峰化和断字字符串的函数,以便您自己的min框架可以接受CSS setter或getter的形式。 这是其所有功能的功能。

JavaScript (The JavaScript)

As you could probably guess, this task is best accomplished with regular expressions:

您可能会猜到,最好用正则表达式完成此任务:

function camelize(str) {	return (str + "").replace(/-\D/g, function(match) {		return match.charAt(1).toUpperCase();	});}camelize("border-bottom-color"); // "borderBottomColor"function hyphenate(str) {	return (str + "").replace(/[A-Z]/g, function(match) {		return "-" + match.toLowerCase();	});}hyphenate("borderBottomColor"); // "border-bottom-color"

A couple of really handy JavaScript String to corresponding String format functions. Instead of expecting strings in only one format, your mini library can now accept both!

几个非常方便JavaScript String与对应的String格式函数。 现在,您的迷你图书馆不再只希望使用一种格式的字符串,而是可以接受两种格式!

翻译自:

转载地址:http://uuvwd.baihongyu.com/

你可能感兴趣的文章
btn按钮之间事件相互调用
查看>>
Entity Framework 4.3.1 级联删除
查看>>
codevs 1163:访问艺术馆
查看>>
冲刺Noip2017模拟赛3 解题报告——五十岚芒果酱
查看>>
并查集
查看>>
sessionStorage
查看>>
代码示例_进程
查看>>
Java中关键词之this,super的使用
查看>>
学习进度
查看>>
“此人不存在”
查看>>
github.com加速节点
查看>>
解密zend-PHP凤凰源码程序
查看>>
python3 序列分片记录
查看>>
Atitit.git的存储结构and 追踪
查看>>
atitit 读书与获取知识资料的attilax的总结.docx
查看>>
B站 React教程笔记day2(3)React-Redux
查看>>
找了一个api管理工具
查看>>
Part 2 - Fundamentals(4-10)
查看>>
使用Postmark测试后端存储性能
查看>>
NSTextView 文字链接的定制化
查看>>