Js常用函数 /** * Convert a style object to a string * @param { Object } style - style object we need to parse * @returns { String } resulting css string * @example * styleObjectToString({ color: 'red', height: '10px'}) // = 'color: red;
/** * Convert a style object to a string * @param { Object } style - style object we need to parse * @returns { String } resulting css string * @example * styleObjectToString({ color: 'red', height: '10px'}) // => 'color: red; height: 10px' */ function styleObjectToString(style) { return Object.keys(style).reduce(function (acc, prop) { return (acc + " " + prop + ": " + (style[prop]) + ";") }, '') } /** * Faster String startsWith alternative * @param { String } str - source string * @param { String } value - test string * @returns { Boolean } - */ function startsWith(str, value) { return str.slice(0, value.length) === value }