Sitemap
WhySoSilent?

WhySoSilent?

We lived in earth ,and think about the world ,ourselves.We have own hobby and dreams.

4 min readSep 28, 2014

Docu test

重写原生浏览器方法以实现新功能

下列代码通过重写浏览器的alert让它可以记录弹窗的次数。

(function() {
var oldAlert = window.alert,
count = 0;
window.alert = function(a) {
count++;
oldAlert(a + “\n You’ve called alert “ + count + “ times now. Stop, it’s evil!”);
};
})();

关于console的恶作剧

关于重写原生方法,这里有个恶作剧大家可以拿去寻开心。Chrome的console.log是支持对文字添加样式的,甚至log图片都可以。于是可以重写掉默认的log方法,把将要log的文字应用到CSS的模糊效果,这样当有人试图调用console.log()的时候,出来的是模糊不清的文字。好冷,我表示没有笑。

的时候会很有用。性能比较见此。顺便说句,!!将一个值方便快速转化为布尔值 !!window=

function () {

this.a = 100;

}

Get WhySoSilent?’s stories in your inbox

Join Medium for free to get updates from this writer.

The components of this string are:

  1. mongodb://
  2. A required prefix to identify that this is a string in the standard connection format.
  3. username:password@
  4. Optional. If specified, the client will attempt to log in to the specific database using these credentials after connecting to the mongod instance.
  5. host1
  6. This the only required part of the URI. It identifies a server address to connect to. It identifies either a hostname, IP address, or UNIX domain socket.
  7. :port1
  8. Optional. The default value is :27017 if not specified.
  9. hostX
  10. Optional. You can specify as many hosts as necessary. You would specify multiple hosts, for example, for connections to replica sets.
  11. :portX
  12. Optional. The default value is :27017 if not specified.
  13. /database
  14. Optional. The name of the database to authenticate if the connection string includes authentication credentials in the form of username:password@. If /database is not specified and the connection string includes credentials, the driver will authenticate to the admin database.
  15. ?options
  16. Connection specific options. See Connection String Options for a full description of these options.
  17. If the connection string does not specify a database/ you must specify a slash (i.e. /) between the last hostN and the question mark that begins the string of options.

EXAMPLE

To describe a connection to a replica set named test, with the following mongod hosts:

  • db1.example.net on port 27017 and
  • db2.example.net on port 2500.

You would use a connection string that resembles the following:

mongodb://db1.example.net,db2.example.net:2500/?replicaSet=te

--

--

WhySoSilent?
WhySoSilent?

Written by WhySoSilent?

We lived in earth ,and think about the world ,ourselves.We have own hobby and dreams.