Java是一種可以撰寫跨平臺應(yīng)用軟件的面向?qū)ο蟮某绦蛟O(shè)計(jì)語言虱歪。Java 技術(shù)具有卓越的通用性匆帚、高效性熬词、平臺移植性和安全性,廣泛應(yīng)用于PC吸重、數(shù)據(jù)中心互拾、游戲控制臺、科學(xué)超級計(jì)算機(jī)嚎幸、移動電話和互聯(lián)網(wǎng)颜矿,同時(shí)擁有全球最大的開發(fā)者專業(yè)社群。
給你Java學(xué)習(xí)路線:html-css-js-jq-javase-數(shù)據(jù)庫-jsp-servlet-Struts2-hibernate-mybatis-spring4-springmvc-ssh-ssm
Java編程script是一門很吊的語言鞭铆,我可能學(xué)了假的JavaScript或衡,哈哈焦影,大家還有什么推薦的车遂,補(bǔ)充送那啥邀請碼。
本文秉承著:你看不懂只能說你還是菜鳥斯辰,我寫的代碼就是很牛舶担。
1、單行寫一個評級組件
“★★★★★☆☆☆☆☆”.slice(5 – rate, 10 – rate);定義一個變量rate是1到5的值彬呻,然后執(zhí)行上面代碼衣陶,看圖
小編推薦一個學(xué)Java的學(xué)習(xí)裙【 六五零,五五四闸氮,六零七 】剪况,無論你是大牛還是小白,是想轉(zhuǎn)行還是想入行都可以來了解一起進(jìn)步一起學(xué)習(xí)蒲跨!裙內(nèi)有開發(fā)工具译断,很多干貨和技術(shù)資料分享!
才發(fā)現(xiàn)插件什么的都弱爆了
2或悲、如何裝逼用代碼罵別人SB
(!(~+[])+{})[--[~+""][+[]]*[~+[]] + ~~!+[]]+({}+[])[[~!+[]]*~+[]]
3孙咪、如何用代碼優(yōu)雅的證明自己NB
這個牛逼了
console.log(([][[]]+[])[+!![]]+([]+{})[!+[]+!![]])
4、JavaScript 錯誤處理的方式的正確姿勢
巡语,舅服你
try {something} catch (e) {window.location. +e.message;}
5翎蹈、從一行代碼里面學(xué)點(diǎn)JavaScript
[].forEach.call($$("*"),function(a){a.style.outline="1px solid #"+(~~(Math.random()*(1<<24))).toString(16)})
翻譯成正常語言就是這樣的
Array.prototype.forEach.call(document.querySelectorAll('*'), dom => dom.style.outline = `1px solid #${parseInt(Math.random() * Math.pow(2,24)).toString(16)}`)
接下來在瀏覽器控制看看:something magic happens
小編推薦一個學(xué)Java的學(xué)習(xí)裙【 六五零,五五四男公,六零七 】荤堪,無論你是大牛還是小白,是想轉(zhuǎn)行還是想入行都可以來了解一起進(jìn)步一起學(xué)習(xí)!裙內(nèi)有開發(fā)工具澄阳,很多干貨和技術(shù)資料分享曙寡!
6、論如何優(yōu)雅的取隨機(jī)字符串
Math.random().toString(16).substring(2) Math.random().toString(36).substring(2)
7寇荧、(10)[“toString”]() === “10”
8举庶、匿名函數(shù)自執(zhí)行
這么多寫法你選擇哪一種?我選擇死亡揩抡。
( function() {}() );( function() {} )();[ function() {}() ];~ function() {}();! function() {}();+ function() {}();- function() {}();delete function() {}();typeof function() {}();void function() {}();new function() {}();new function() {};var f = function() {}();1, function() {}();1 ^ function() {}();1 > function() {}();// ...
9户侥、另外一種undefined
從來不需要聲明一個變量的值是undefined,因?yàn)镴avaScript會自動把一個未賦值的變量置為undefined峦嗤。所有如果你在代碼里這么寫蕊唐,會被鄙視的
var data = undefined;
但是如果你就是強(qiáng)迫癥發(fā)作,一定要再聲明一個暫時(shí)沒有值的變量的時(shí)候賦上一個undefined烁设。那你可以考慮這么做:
var data = void 0; // undefined
void在JavaScript中是一個操作符替梨,對傳入的操作不執(zhí)行并且返回undefined。void后面可以跟()來用装黑,例如void(0)副瀑,看起來是不是很熟悉?沒錯恋谭,在HTML里阻止帶href的默認(rèn)點(diǎn)擊操作時(shí)糠睡,都喜歡把href寫成javascript:void(0),實(shí)際上也是依靠void操作不執(zhí)行的意思疚颊。
當(dāng)然狈孔,除了出于裝逼的原因外,實(shí)際用途上不太贊成使用void材义,因?yàn)関oid的出現(xiàn)是為了兼容早起ECMAScript標(biāo)準(zhǔn)中沒有undefined屬性均抽。void 0的寫法讓代碼晦澀難懂。
10其掂、論如何優(yōu)雅的取整
var a = ~~2.33var b= 2.33 | 0var c= 2.33 >> 0
11油挥、如何優(yōu)雅的實(shí)現(xiàn)金錢格式化:1234567890 –> 1,234,567,890
用正則魔法實(shí)現(xiàn):
var test1 = '1234567890'var format = test1.replace(/B(?=(d{3})+(?!d))/g, ',')console.log(format) // 1,234,567,890
非正則的優(yōu)雅實(shí)現(xiàn):
function formatCash(str) {return str.split('').reverse().reduce((prev, next, index) => {return ((index % 3) ? next : (next + ',')) + prev })}console.log(formatCash('1234567890')) // 1,234,567,890
12、這個我服清寇,還有這個你很機(jī)智
我服
while (1) {alert('牛逼你把我關(guān)了啊')}
你很機(jī)智喘漏,好一個障眼法
清除緩存: 清除緩存
13、逗號運(yùn)算符
var a = 0; var b = ( a++, 99 ); console.log(a); // 1console.log(b); // 99
14华烟、論如何最佳的讓兩個整數(shù)交換數(shù)值
常規(guī)辦法:
var a=1,b=2;a += b;b = a - b;a -= b;
缺點(diǎn)也很明顯翩迈,整型數(shù)據(jù)溢出,對于32位字符最大表示數(shù)字是2147483647盔夜,如果是2147483645和2147483646交換就失敗了负饲。
黑科技辦法:
a ^= b;b ^= a;a ^= b;
哈哈
堤魁,看不懂的童鞋建議去補(bǔ)習(xí)一下C語言的位操作,我就不去復(fù)習(xí)了返十,以前學(xué)嵌入式時(shí)候?qū)W的位操作都忘了
15妥泉、實(shí)現(xiàn)標(biāo)準(zhǔn)JSON的深拷貝
var a = {a: 1,b: { c: 1, d: 2 }}var b=JSON.parse(JSON.stringify(a))
不考慮IE的情況下,標(biāo)準(zhǔn)JSON格式的對象蠻實(shí)用洞坑,不過對于undefined和function的會忽略掉盲链。
16、不用Number迟杂、parseInt和parseFloat和方法把”1″字符串轉(zhuǎn)換成數(shù)字
哈哈刽沾,不準(zhǔn)用強(qiáng)制類型轉(zhuǎn)換,那么就想到了強(qiáng)大了隱式轉(zhuǎn)換
var a =1 +a
17排拷、如何裝逼的寫出”hello world!”
滾動條很長哦
([]+[][(![]+[])[!+[]+!![]+!![]]+([]+{})[+!![]]+(!![]+[])[+!![]]+(!![]+[])[+[]]][([]+{})[!+[]+!![]+!![]+!![]+!![]]+([]+{})[+!![]]+([][[]]+[])[+!![]]+(![]+[])[!+[]+!![]+!![]]+(!![]+[])[+[]]+(!![]+[])[+!![]]+([][[]]+[])[+[]]+([]+{})[!+[]+!![]+!![]+!![]+!![]]+(!![]+[])[+[]]+([]+{})[+!![]]+(!![]+[])[+!![]]]((!![]+[])[+!![]]+([][[]]+[])[!+[]+!![]+!![]]+(!![]+[])[+[]]+([][[]]+[])[+[]]+(!![]+[])[+!![]]+([][[]]+[])[+!![]]+([]+{})[!+[]+!![]+!![]+!![]+!![]+!![]+!![]]+(![]+[])[!+[]+!![]]+([]+{})[+!![]]+([]+{})[!+[]+!![]+!![]+!![]+!![]]+(+{}+[])[+!![]]+(!![]+[])[+[]]+([][[]]+[])[!+[]+!![]+!![]+!![]+!![]]+([]+{})[+!![]]+([][[]]+[])[+!![]])())[+[]]+([][[]]+[])[!+[]+!![]+!![]]+(![]+[])[!+[]+!![]]+(![]+[])[!+[]+!![]]+([]+{})[+!![]]+([]+{})[!+[]+!![]+!![]+!![]+!![]+!![]+!![]]+[][(![]+[])[!+[]+!![]+!![]]+([]+{})[+!![]]+(!![]+[])[+!![]]+(!![]+[])[+[]]][([]+{})[!+[]+!![]+!![]+!![]+!![]]+([]+{})[+!![]]+([][[]]+[])[+!![]]+(![]+[])[!+[]+!![]+!![]]+(!![]+[])[+[]]+(!![]+[])[+!![]]+([][[]]+[])[+[]]+([]+{})[!+[]+!![]+!![]+!![]+!![]]+(!![]+[])[+[]]+([]+{})[+!![]]+(!![]+[])[+!![]]]((!![]+[])[+!![]]+([][[]]+[])[!+[]+!![]+!![]]+(!![]+[])[+[]]+([][[]]+[])[+[]]+(!![]+[])[+!![]]+([][[]]+[])[+!![]]+([]+{})[!+[]+!![]+!![]+!![]+!![]+!![]+!![]]+([][[]]+[])[+[]]+([][[]]+[])[+!![]]+([][[]]+[])[!+[]+!![]+!![]]+(![]+[])[!+[]+!![]+!![]]+([]+{})[!+[]+!![]+!![]+!![]+!![]]+(+{}+[])[+!![]]+([]+[][(![]+[])[!+[]+!![]+!![]]+([]+{})[+!![]]+(!![]+[])[+!![]]+(!![]+[])[+[]]][([]+{})[!+[]+!![]+!![]+!![]+!![]]+([]+{})[+!![]]+([][[]]+[])[+!![]]+(![]+[])[!+[]+!![]+!![]]+(!![]+[])[+[]]+(!![]+[])[+!![]]+([][[]]+[])[+[]]+([]+{})[!+[]+!![]+!![]+!![]+!![]]+(!![]+[])[+[]]+([]+{})[+!![]]+(!![]+[])[+!![]]]((!![]+[])[+!![]]+([][[]]+[])[!+[]+!![]+!![]]+(!![]+[])[+[]]+([][[]]+[])[+[]]+(!![]+[])[+!![]]+([][[]]+[])[+!![]]+([]+{})[!+[]+!![]+!![]+!![]+!![]+!![]+!![]]+(![]+[])[!+[]+!![]]+([]+{})[+!![]]+([]+{})[!+[]+!![]+!![]+!![]+!![]]+(+{}+[])[+!![]]+(!![]+[])[+[]]+([][[]]+[])[!+[]+!![]+!![]+!![]+!![]]+([]+{})[+!![]]+([][[]]+[])[+!![]])())[!+[]+!![]+!![]]+([][[]]+[])[!+[]+!![]+!![]])()([][(![]+[])[!+[]+!![]+!![]]+([]+{})[+!![]]+(!![]+[])[+!![]]+(!![]+[])[+[]]][([]+{})[!+[]+!![]+!![]+!![]+!![]]+([]+{})[+!![]]+([][[]]+[])[+!![]]+(![]+[])[!+[]+!![]+!![]]+(!![]+[])[+[]]+(!![]+[])[+!![]]+([][[]]+[])[+[]]+([]+{})[!+[]+!![]+!![]+!![]+!![]]+(!![]+[])[+[]]+([]+{})[+!![]]+(!![]+[])[+!![]]]((!![]+[])[+!![]]+([][[]]+[])[!+[]+!![]+!![]]+(!![]+[])[+[]]+([][[]]+[])[+[]]+(!![]+[])[+!![]]+([][[]]+[])[+!![]]+([]+{})[!+[]+!![]+!![]+!![]+!![]+!![]+!![]]+([][[]]+[])[!+[]+!![]+!![]]+(![]+[])[!+[]+!![]+!![]]+([]+{})[!+[]+!![]+!![]+!![]+!![]]+(+{}+[])[+!![]]+([]+[][(![]+[])[!+[]+!![]+!![]]+([]+{})[+!![]]+(!![]+[])[+!![]]+(!![]+[])[+[]]][([]+{})[!+[]+!![]+!![]+!![]+!![]]+([]+{})[+!![]]+([][[]]+[])[+!![]]+(![]+[])[!+[]+!![]+!![]]+(!![]+[])[+[]]+(!![]+[])[+!![]]+([][[]]+[])[+[]]+([]+{})[!+[]+!![]+!![]+!![]+!![]]+(!![]+[])[+[]]+([]+{})[+!![]]+(!![]+[])[+!![]]]((!![]+[])[+!![]]+([][[]]+[])[!+[]+!![]+!![]]+(!![]+[])[+[]]+([][[]]+[])[+[]]+(!![]+[])[+!![]]+([][[]]+[])[+!![]]+([]+{})[!+[]+!![]+!![]+!![]+!![]+!![]+!![]]+(![]+[])[!+[]+!![]]+([]+{})[+!![]]+([]+{})[!+[]+!![]+!![]+!![]+!![]]+(+{}+[])[+!![]]+(!![]+[])[+[]]+([][[]]+[])[!+[]+!![]+!![]+!![]+!![]]+([]+{})[+!![]]+([][[]]+[])[+!![]])())[!+[]+!![]+!![]]+([][[]]+[])[!+[]+!![]+!![]])()(([]+{})[+[]])[+[]]+(!+[]+!![]+!![]+!![]+!![]+!![]+!![]+[])+(!+[]+!![]+!![]+!![]+!![]+!![]+!![]+[]))+([]+{})[+!![]]+(!![]+[])[+!![]]+(![]+[])[!+[]+!![]]+([][[]]+[])[!+[]+!![]]+[][(![]+[])[!+[]+!![]+!![]]+([]+{})[+!![]]+(!![]+[])[+!![]]+(!![]+[])[+[]]][([]+{})[!+[]+!![]+!![]+!![]+!![]]+([]+{})[+!![]]+([][[]]+[])[+!![]]+(![]+[])[!+[]+!![]+!![]]+(!![]+[])[+[]]+(!![]+[])[+!![]]+([][[]]+[])[+[]]+([]+{})[!+[]+!![]+!![]+!![]+!![]]+(!![]+[])[+[]]+([]+{})[+!![]]+(!![]+[])[+!![]]]((!![]+[])[+!![]]+([][[]]+[])[!+[]+!![]+!![]]+(!![]+[])[+[]]+([][[]]+[])[+[]]+(!![]+[])[+!![]]+([][[]]+[])[+!![]]+([]+{})[!+[]+!![]+!![]+!![]+!![]+!![]+!![]]+([][[]]+[])[+[]]+([][[]]+[])[+!![]]+([][[]]+[])[!+[]+!![]+!![]]+(![]+[])[!+[]+!![]+!![]]+([]+{})[!+[]+!![]+!![]+!![]+!![]]+(+{}+[])[+!![]]+([]+[][(![]+[])[!+[]+!![]+!![]]+([]+{})[+!![]]+(!![]+[])[+!![]]+(!![]+[])[+[]]][([]+{})[!+[]+!![]+!![]+!![]+!![]]+([]+{})[+!![]]+([][[]]+[])[+!![]]+(![]+[])[!+[]+!![]+!![]]+(!![]+[])[+[]]+(!![]+[])[+!![]]+([][[]]+[])[+[]]+([]+{})[!+[]+!![]+!![]+!![]+!![]]+(!![]+[])[+[]]+([]+{})[+!![]]+(!![]+[])[+!![]]]((!![]+[])[+!![]]+([][[]]+[])[!+[]+!![]+!![]]+(!![]+[])[+[]]+([][[]]+[])[+[]]+(!![]+[])[+!![]]+([][[]]+[])[+!![]]+([]+{})[!+[]+!![]+!![]+!![]+!![]+!![]+!![]]+(![]+[])[!+[]+!![]]+([]+{})[+!![]]+([]+{})[!+[]+!![]+!![]+!![]+!![]]+(+{}+[])[+!![]]+(!![]+[])[+[]]+([][[]]+[])[!+[]+!![]+!![]+!![]+!![]]+([]+{})[+!![]]+([][[]]+[])[+!![]])())[!+[]+!![]+!![]]+([][[]]+[])[!+[]+!![]+!![]])()([][(![]+[])[!+[]+!![]+!![]]+([]+{})[+!![]]+(!![]+[])[+!![]]+(!![]+[])[+[]]][([]+{})[!+[]+!![]+!![]+!![]+!![]]+([]+{})[+!![]]+([][[]]+[])[+!![]]+(![]+[])[!+[]+!![]+!![]]+(!![]+[])[+[]]+(!![]+[])[+!![]]+([][[]]+[])[+[]]+([]+{})[!+[]+!![]+!![]+!![]+!![]]+(!![]+[])[+[]]+([]+{})[+!![]]+(!![]+[])[+!![]]]((!![]+[])[+!![]]+([][[]]+[])[!+[]+!![]+!![]]+(!![]+[])[+[]]+([][[]]+[])[+[]]+(!![]+[])[+!![]]+([][[]]+[])[+!![]]+([]+{})[!+[]+!![]+!![]+!![]+!![]+!![]+!![]]+([][[]]+[])[!+[]+!![]+!![]]+(![]+[])[!+[]+!![]+!![]]+([]+{})[!+[]+!![]+!![]+!![]+!![]]+(+{}+[])[+!![]]+([]+[][(![]+[])[!+[]+!![]+!![]]+([]+{})[+!![]]+(!![]+[])[+!![]]+(!![]+[])[+[]]][([]+{})[!+[]+!![]+!![]+!![]+!![]]+([]+{})[+!![]]+([][[]]+[])[+!![]]+(![]+[])[!+[]+!![]+!![]]+(!![]+[])[+[]]+(!![]+[])[+!![]]+([][[]]+[])[+[]]+([]+{})[!+[]+!![]+!![]+!![]+!![]]+(!![]+[])[+[]]+([]+{})[+!![]]+(!![]+[])[+!![]]]((!![]+[])[+!![]]+([][[]]+[])[!+[]+!![]+!![]]+(!![]+[])[+[]]+([][[]]+[])[+[]]+(!![]+[])[+!![]]+([][[]]+[])[+!![]]+([]+{})[!+[]+!![]+!![]+!![]+!![]+!![]+!![]]+(![]+[])[!+[]+!![]]+([]+{})[+!![]]+([]+{})[!+[]+!![]+!![]+!![]+!![]]+(+{}+[])[+!![]]+(!![]+[])[+[]]+([][[]]+[])[!+[]+!![]+!![]+!![]+!![]]+([]+{})[+!![]]+([][[]]+[])[+!![]])())[!+[]+!![]+!![]]+([][[]]+[])[!+[]+!![]+!![]])()(([]+{})[+[]])[+[]]+(!+[]+!![]+[])+(+!![]+[]))
居然能運(yùn)行侧漓,牛逼的隱式轉(zhuǎn)換
小編推薦一個學(xué)Java的學(xué)習(xí)裙【 六五零,五五四监氢,六零七 】布蔗,無論你是大牛還是小白,是想轉(zhuǎn)行還是想入行都可以來了解一起進(jìn)步一起學(xué)習(xí)浪腐!裙內(nèi)有開發(fā)工具纵揍,很多干貨和技術(shù)資料分享!
18牛欢、parseInt(0.0000008) === 8
19骡男、++[[]][+[]]+[+[]] == 10
強(qiáng)大的隱式轉(zhuǎn)換,23333
20傍睹、0.1 + 0.2 == 0.3
0.1 +0.2 == 0.3?竟然是不成立的。犹菱。拾稳。。所以這就是為什么數(shù)據(jù)庫存儲對于貨幣的最小單位都是分腊脱。
簡單說访得,0.1和0.2的二進(jìn)制浮點(diǎn)表示都不是精確的,所以相加后不是0.3陕凹,接近(不等于)
0.30000000000000004悍抑。
所以,比較數(shù)字時(shí)杜耙,應(yīng)該有個寬容值搜骡。ES6中這個寬容值被預(yù)定義了:Number.EPSILON。
21佑女、最短的代碼實(shí)現(xiàn)數(shù)組去重
[...new Set([1, "1", 2, 1, 1, 3])]
前不久面試阿里就問了這道題记靡,哈哈谈竿,所以也寫上一下
22、用最短的代碼實(shí)現(xiàn)一個長度為m(6)且值都n(8)的數(shù)組
Array(6).fill(8)
這個夠短了吧摸吠,好像是當(dāng)初哪里看到的一個面試題空凸,就自己想到了ES6的一些API
23、短路表達(dá)式
條件判斷
var a = b && 1// 相當(dāng)于if (b) {a = 1} else {a = b}var a = b || 1// 相當(dāng)于if (b) {a = b} else {a = 1}
24寸痢、JavaScript版迷宮
逃出迷宮呀洲,2333
25、取出一個數(shù)組中的最大值和最小值
var numbers = [5, 458 , 120 , -215 , 228 , 400 , 122205, -85411]; var maxInNumbers = Math.max.apply(Math, numbers); var minInNumbers = Math.min.apply(Math, numbers);
26啼止、將argruments對象轉(zhuǎn)換成數(shù)組
var argArray = Array.prototype.slice.call(arguments);或者ES6:var argArray = Array.from(arguments)
27两嘴、javascript高逼格之Function構(gòu)造函數(shù)
很多JavaScript教程都告訴我們,不要直接用內(nèi)置對象的構(gòu)造函數(shù)來創(chuàng)建基本變量族壳,例如var arr = new Array(2); 的寫法就應(yīng)該用var arr = [1, 2];的寫法來取代憔辫。
但是,F(xiàn)unction構(gòu)造函數(shù)(注意是大寫的Function)有點(diǎn)特別仿荆。Function構(gòu)造函數(shù)接受的參數(shù)中贰您,第一個是要傳入的參數(shù)名,第二個是函數(shù)內(nèi)的代碼(用字符串來表示)拢操。
var f = new Function('a', 'alert(a)');f('jawil'); // 將會彈出窗口顯示jawil
這種方式可以根據(jù)傳入字符串內(nèi)容來創(chuàng)建一個函數(shù) 是不是高大上锦亦?!
小編推薦一個學(xué)Java的學(xué)習(xí)裙【 六五零令境,五五四杠园,六零七 】,無論你是大牛還是小白舔庶,是想轉(zhuǎn)行還是想入行都可以來了解一起進(jìn)步一起學(xué)習(xí)抛蚁!裙內(nèi)有開發(fā)工具,很多干貨和技術(shù)資料分享惕橙!
28瞧甩、從一個數(shù)組中找到一個數(shù),O(n)的算法弥鹦,找不到就返回 null肚逸。
正常的版本:
function find (x, y) {for ( let i = 0; i < x.length; i++ ) {if ( x[i] == y ) return i;}return null;}let arr = [0,1,2,3,4,5]console.log(find(arr, 2))console.log(find(arr, 8))
結(jié)果到了函數(shù)式成了下面這個樣子(好像上面的那些代碼在下面若影若現(xiàn),不過又有點(diǎn)不太一樣彬坏,為了消掉if語言朦促,讓其看上去更像一個表達(dá)式,動用了 ? 號表達(dá)式):
//函數(shù)式的版本const find = ( f => f(f) ) ( f =>(next => (x, y, i = 0) =>( i >= x.length) ? null :( x[i] == y ) ? i :next(x, y, i+1))((...args) =>(f(f))(...args)))let arr = [0,1,2,3,4,5]console.log(find(arr, 2))console.log(find(arr, 8))
如何讀懂并寫出裝逼的函數(shù)式代碼
最后奉勸大家一句:莫裝逼栓始、白了少年頭务冕,2333。混滔。洒疚。