博文

目前显示的是 十一月, 2014的博文

Javascript对象创建的几种方式

本文是Nicholas的《Javascript高级程序设计》6.2章的读书笔记,仅在加强记忆 工厂模式。即用一个函数来生成类的实例 function creator(name, age, job){ var o = {}; o.name = name; o.age = age; o.job = job; o.getName = function(){ return this.name; }; return o; } var person1 = creator('siglud', 10, 'Engineer'); var person2 = creator('ethlin', 12, 'Doctor'); console.log(person1.getName == person2.getName); 这种方法的很好理解,就是构造一个能返回一个类实例的函数,但是弊端有两个,一是无法用反射知道一个对象的类型,因为这个对象的类型是Object(例子中我用{}来代替);二是getName作为一个函数本来是可以复用的,但是却其实生成了两个,所以在最后的console log中打印出了false 生成器模式。原版翻译为构造函数模式,但是这个“构造函数”明显是和C语言中的构造函数不是一个东西,所以我换个说法,其本质就是把函数本身作为一个类,用new关键字来生成一个新的函数(类)对象,因为JS中函数本身也是一个对象 function Person(name, age, job){ this.name = name; this.age = age; this.job = job; this.getName = function(){ return this.name; } } var person3 = new Person('siglud', 10, 'Engineer'); var person4 = new Person('ethlin', 12, 'Doctor'); console.log(pers

在CentOS 7上用Apache+PHP建立虚拟主机

默认的CentOS就自带了Apache,本篇主要是用系统自带的Apache来完成的 首先先新建一个配置文件 vim /etc/httpd/conf.d/site.conf 内容如下: <VirtualHost *:80> DocumentRoot /home/www ServerName siglud.com.cn     <Directory />         Require all granted         AllowOverride All         DirectoryIndex index.php index.htm     </Directory> </VirtualHost> 然后systemctl restart httpd 打开iptables的端口 iptables -I INPUT -p tcp --dport 80 -j ACCEPT /usr/libexec/iptables/iptables.init save 这个时候去访问大部分都会收到403了,原因在于selinux chcon -Rv --type=httpd_sys_content_t /home/www 如果这个时候报错 那么执行 chcon -R -h system_u:object_r:usr_t /home/www/ 之后再执行它就可以了