随笔分类 - javascript
摘要:http://mslog.sinaapp.com/archives/33今天在博客园看了一位哥的按需加载图片博客,将代码做成一个函数封装下,直接拿来主义用在我的站上,12345678910111213141516varfn=function(){ $("img").each(function(){//遍历所有图片 varothis=$(this),//当前图片对象 top=othis.offset().top-$(window).scrollTop();//计算图片top - 滚动条top if(top>$(window).height()){//如果该图片不可见 .
阅读全文
摘要:// all environmentsapp.configure(function(){ app.set('title', 'My Application');})// development onlyapp.configure('development', function(){ app.set('db uri', 'localhost/dev');})// production onlyapp.configure('production', function(){ app.set('db
阅读全文
摘要:var express = require('express');var app = express();app.get('/', function(req, res){ res.send('hello world');});app.listen(3001);非常简单,此代码暂时无视图模板样式等概念
阅读全文
摘要:function Animal(){ this.species = "动物";}function Cat(name, color){ this.name = name; this.color = color;}Cat.prototype = new Animal();Cat.prototype.constructor = Cat; //重新把Cat的构造函数指回Catvar c2 = new Cat("大黄", "黄色滴");console.log(c2.name);console.log(c2.species);console.lo
阅读全文
摘要:function Cat(name, color){ this.name = name; this.color = color;}Cat.prototype.type = "猫科动物";Cat.prototype.eat = function(){ console.log("吃鱼吃老鼠");}var c1 = new Cat("Tom", "black");console.log(c1.type);c1.eat();//检测类与对象人性关系:isPrototypeOfCat.prototype.isPrototyp
阅读全文
摘要:function Shape(){ var init = function(){ } //模拟构造函数 init(); this.x = 1; //公有属性 this.y = 2; this.draw = function(){ console.log( this.x + this.y); }; //公有方法}var ashape = new Shape();console.log(ashape.x);ashape.draw();类属性\方法的定义:Shape.count = 10Shape.staticMethod = function(){}
阅读全文
摘要:var mongodb =require('mongodb');var server = new mongodb.Server('localhost', 27018, {auto_reconnect:true});var db = new mongodb.Db('mydb', server, {safe:true});db.open(function(err, db){ if(!err){ console.log('connect'); }else{ console.log(err); }});
阅读全文
摘要:#coding=utf8def func1(count): for i in range(count): print i print i #4func1(5)def func2(count): def f(): for i in range(count): print i f() print i #抛错func2(5)python和js一样,应该是没有块级作用域的,可以用函数的函数来模拟块级作用域,以免变量过多造成数据污染。而js模拟块级作用域的方法是用函数表达式+括号:function outputFunc(co...
阅读全文
摘要:node.js处理都是异步的var fs = require("fs");fs.readFile("a.txt", 'utf8', function(error, file){ if(error) throw error; console.log("我读完文件了"); console.log(file)});console.log("我不会被阻塞的"); js的模拟sleep函数,function sleep(milliSeconds){ var startTime = new Date().get
阅读全文
摘要:一、修改server.jsvar http = require("http");var url = require("url"); //导入内置url模块function start(route){ function onRequest(request, response){ var pathname = url.parse(request.url).pathname; //提取url console.log("Request received."); console.log("Request for " + pa
阅读全文
摘要:在第一篇笔记中,了解到,使用node.js 内置模块的方法:var http = require("http");创建自己的模块的方法其实就是将其功能代码导出到请求这个模块的脚本。server.js代码如下,var http = require("http");function start(){ function onRequest(request, response){ console.log("Request received.") response.writeHead(200, {"Content-Type"
阅读全文
摘要:var http = require("http");http.createServer(function(request, response){ response.writeHead(200, {"Content-Type": "text/plain"}); response.write("Hello,World"); response.end();}).listen(8888);保存文件为server.js, 在命令行里运行代码node server.js在浏览器地址栏输入 http://localhost:8
阅读全文
浙公网安备 33010602011771号