Few days back I was working on a theme design and faced a very rare issue. The issue we faced was magento search not working in Magento Responsive Magento Web Design theme which is by default provided with the bundle of magento.
I took few steps to make it working and found out many solutions which can work for
javascript 是一门很灵活的语言,也是一门有缺陷的语言.
比如我们今天要谈的,如何用面向对象的手法来封装javascript ,javascript是没有类的概念的.
所以今天谈到的封装,其实就是用javascript的函数来实现的.
var People{
name:'一介布衣',
age:'30'
};
这就是javascript中的一个对象,里面封装了2个属性.
实例化一个对象的实例 people
var people=new People();
console.log(people.name,people.age); //一介布衣,30
如果我们需要在函数里返回一个对象,如下代码:
function CreateP… Read More
1. Node.js的模块载入方式与机制
Node.js中模块可以通过文件路径或名字获取模块的引用。模块的引用会映射到一个js文件路径,除非它是一个Node内置模块。Node的内置模块公开了一些常用的API给开发者,并且它们在Node进程开始的时候就预加载了。
其它的如通过NPM安装的第三方模块(third-party modules)或本地模块(local modules),每个模块都会暴露一个公开的API。以便开发者可以导入。如
var mod = require('module_name')
此句执行后,Node内部会载入内置模块或通过NPM安装的模块。require函数会返回一个对象,该对象公… Read More
1. 先说说各自的用法:
How do I read files in node.js?
fs = require('fs');
fs.readFile(file, [encoding], [callback]);
// file = (string) filepath of the file to read
encoding is an optional parameter that specifies the type of encoding to read the file. Possible encodings are ‘ascii’, ‘utf8’, and ‘base64’. If no encoding i… Read More