function User(name, age) { this.name = name || "Oliver Queen"; this.age = age || 27; } var user1 = new User(); console.log(user1.name); // Oliver Queen console.log(user1.age); // 27
var user2 = new User("Barry Allen", 25); console.log(user2.name); // Barry Allen console.log(user2.age); // 25
var length = array.length; for (var i = 0; i < length; i++) { console.log(array[i]); }
为了更简洁,可以这么写:
1 2 3
for (var i = 0, length = array.length; i < length; i++) { console.log(array[i]); }
6) 检测对象中的属性
当你需要检查某些属性是否存在,避免运行未定义的函数或属性时,这个技巧非常有用。如果你打算编写跨浏览器代码,你也可能会用到这个技术。例如,我们假设你需要编写与旧版Internet Explorer 6兼容的代码,并且想要使用document.querySelector()来通过ID获取某些元素。 但是,在现代浏览器中,这个函数不存在。所以,要检查这个函数是否存在,你可以使用in运算符。看下这个例子:
1 2 3 4 5
if ('querySelector' in document) { document.querySelector("#id"); } else { document.getElementById("id"); }
var elements = document.querySelectorAll("p"); // NodeList var arrayElements = [].slice.call(elements); // 现在已经转换成数组了 var arrayElements = Array.from(elements); // 把NodeList转换成数组的另外一个方法
12) 对数组元素进行洗牌
如果要像外部库Lodash那样对数据元素重新洗牌,只需使用这个技巧:
1 2 3 4
var list = [1, 2, 3]; console.log(list.sort(function() { return Math.random() - 0.5 })); // [2,1,3]
For installing device HUAWEI E3131 in CentOS 6.4 Linux you have to follow instructions below. Can be used to send SMS by AT command and also to establish HiSpeed Mobile Internet connection.
##Install requirements
You have to download usb_modeswitch and data with configurations.
he session is still attached on another terminal. The server hasn’t detected the network outage on that connection: it only detects the outage when it tries to send a packet and gets an error back or no response after a timeout, but this hasn’t happened yet. You’re in a common situation where the client detected the outage because it tried to send some input and failed, but the server is just sitting there waiting for input. Eventually the server will send a keepalive packet and detect that the connection is dead.
In the meantime, use the -d option to detach the screen session from the terminal where it’s in.
1 2
screen -r -d 30608 screen -rd is pretty much the standard way to attach to an
MySQL provides an easy mechanism for writing the results of a select statement into a text file on the server. Using extended options of the INTO OUTFILE nomenclature, it is possible to create a comma separated value (CSV) which can be imported into a spreadsheet application such as OpenOffice or Excel or any other applciation which accepts data in CSV format.
Given a query such as
1
SELECT order_id,product_name,qty FROM orders
which returns three columns of data, the results can be placed into the file /tmo/orders.txt using the query:
1 2
SELECT order_id,product_name,qty FROM orders INTO OUTFILE '/tmp/orders.txt'
This will create a tab-separated file, each row on its own line. To alter this behavior, it is possible to add modifiers to the query:
1 2 3 4 5
SELECT order_id,product_name,qty FROM orders INTO OUTFILE '/tmp/orders.csv' FIELDS TERMINATED BY ',' ENCLOSED BY '"' LINES TERMINATED BY '\n'
In this example, each field will be enclosed in “double quotes,” the fields will be separated by commas, and each row will be output on a new line separated by a newline (\n). Sample output of this command would look like:
Keep in mind that the output file must not already exist and that the user MySQL is running as has write permissions to the directory MySQL is attempting to write the file to.
Note: both base-url and base-url-secure values must contain the URL’s scheme, http:// or https://, and a trailing slash /.
Then clear the cache:
php bin/magento cache:flush
Troubleshooting Clear current values from the database Can happen that the above command doesn’t works as expected and you still have some url pointing to the old base-url. In these cases you have to clear some values in your db.
Open the Magento 2 database with your favorite MySQL tool then go to the core_config_data table.
Search for rows having these values in the column path (note that there could be more than one row for each value):
“web/unsecure/base_url”
“web/secure/base_url” Delete these rows (Magento will recreate them).
Now you can set the base-url value using the above CLI command.
Single-Store Mode option enabled If you have the Single-Store Mode option enabled this could bring to some problem with setting the base-url with the command line.
In this case you should modify the base-url using only the command line and not the Magento’s Admin Panel. If you already saved the Base url field value using the Admin Panel you should clear values within the Magento’s core_config_data table as described above.
Until that command is available, you can string docker commands together with other unix commands to get what you need. Here is an example on how to clean up old containers that are weeks old.
cd ~/ffmpeg_sources curl -O http://www.tortall.net/projects/yasm/releases/yasm-1.2.0.tar.gz tar xzvf yasm-1.2.0.tar.gz cd yasm-1.2.0 ./configure --prefix="$HOME/ffmpeg_build" --bindir="$HOME/bin" make make install make distclean . ~/.bash_profile
cd ~/ffmpeg_sources git clone --depth 1 git://git.videolan.org/x264 cd x264 ./configure --prefix="$HOME/ffmpeg_build" --bindir="$HOME/bin" --enable-static make make install make distclean
cd ~/ffmpeg_sources git clone --depth 1 git://github.com/mstorsjo/fdk-aac.git cd fdk-aac autoreconf -fiv ./configure --prefix="$HOME/ffmpeg_build" --disable-shared make make install make distclean
cd ~/ffmpeg_sources curl -L -O http://downloads.sourceforge.net/project/lame/lame/3.99/lame-3.99.5.tar.gz tar xzvf lame-3.99.5.tar.gz cd lame-3.99.5 ./configure --prefix="$HOME/ffmpeg_build" --bindir="$HOME/bin" --disable-shared --enable-nasm make make install make distclean
cd ~/ffmpeg_sources curl -O http://downloads.xiph.org/releases/opus/opus-1.0.3.tar.gz tar xzvf opus-1.0.3.tar.gz cd opus-1.0.3 ./configure --prefix="$HOME/ffmpeg_build" --disable-shared make make install make distclean
cd ~/ffmpeg_sources curl -O http://downloads.xiph.org/releases/ogg/libogg-1.3.1.tar.gz tar xzvf libogg-1.3.1.tar.gz cd libogg-1.3.1 ./configure --prefix="$HOME/ffmpeg_build" --disable-shared make make install make distclean
cd ~/ffmpeg_sources curl -O http://downloads.xiph.org/releases/vorbis/libvorbis-1.3.3.tar.gz tar xzvf libvorbis-1.3.3.tar.gz cd libvorbis-1.3.3 ./configure --prefix="$HOME/ffmpeg_build" --with-ogg="$HOME/ffmpeg_build" --disable-shared make make install make distclean
cd ~/ffmpeg_sources git clone --depth 1 https://chromium.googlesource.com/webm/libvpx cd libvpx git checkout tags/v1.3.0 ./configure --prefix="$HOME/ffmpeg_build" --disable-examples make make install make clean
cd ~/ffmpeg_sources curl -O http://downloads.xiph.org/releases/theora/libtheora-1.1.1.tar.gz tar xzvf libtheora-1.1.1.tar.gz cd libtheora-1.1.1 ./configure --prefix="$HOME/ffmpeg_build" --with-ogg="$HOME/ffmpeg_build" --disable-examples --disable-shared --disable-sdltest --disable-vorbistest make make install make distclean
yum -y install freetype-devel speex-devel
cd ~/ffmpeg_sources git clone --depth 1 git://source.ffmpeg.org/ffmpeg cd ffmpeg PKG_CONFIG_PATH="$HOME/ffmpeg_build/lib/pkgconfig" export PKG_CONFIG_PATH ./configure --prefix="$HOME/ffmpeg_build" --extra-cflags="-I$HOME/ffmpeg_build/include" --extra-ldflags="-L$HOME/ffmpeg_build/lib" --bindir="$HOME/bin" --extra-libs="-ldl" --enable-gpl --enable-nonfree --enable-libfdk_aac --enable-libmp3lame --enable-libopus --enable-libvorbis --enable-libvpx --enable-libx264 --enable-libfreetype --enable-libspeex --enable-libtheora make make install make distclean hash -r . ~/.bash_profile
cd ~/ffmpeg_sources/ffmpeg/tools make qt-faststart cp qt-faststart /usr/bin ldconfig cd