This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
pragma solidity ^ 0.4.17; | |
contract LoveRose { | |
address public ceoAddress; | |
struct Rose { | |
uint64 birthTime; | |
address buyer; | |
uint value; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* 迭代器示例 */ | |
var agg = (function() { | |
var index = 0, | |
data = [1,2,3,4,5,6]; | |
length = data.length; | |
var api = { | |
next: function() { | |
if(!this.hasNext()) { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var myevent = { | |
// ... | |
stop: function (e) { | |
//其他 | |
if(typeof e.preventDefault === "function") { | |
e.preventDefault(); | |
} | |
if(typeof e.stopPropagation === "function") { | |
e.stopPropagation(); | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var getName = function(){ | |
return "Bob"; | |
} | |
var getSex = function(){ | |
return "man"; | |
} | |
var getUserInfo = function(){ | |
var info = getName() + getSex(); | |
return info; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//旧的第三方代码 | |
function getSomething(str1, str2, str3) { | |
// do some thing | |
console.log("Old getSomething"); | |
return str1 + str2 + str3; | |
} | |
//自己的代码 | |
var str1 = "a", | |
str2 = "b", |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var SimpleHandler = function() { }; | |
SimpleHandler.prototype = { | |
request: function(method, url, callback, postVars) { | |
var xhr = this.createXhrObject(); | |
xhr.onreadystatechange = function() { | |
// do some things | |
}; | |
xhr.open(method. url, true); | |
xhr.send(postVars); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//父构造函数 | |
function CarMaker() { } | |
//所有子类通用方法 | |
CarMaker.prototype.drive = function () { | |
console.log( "Vroom, I have " + this.doors + " doors"); | |
}; | |
//静态工厂方法 子类无法继承 | |
CarMaker.factory = function(type) { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//父构造函数 | |
function CarMaker() { } | |
//所有子类通用方法 | |
CarMaker.prototype.drive = function () { | |
console.log( "Vroom, I have " + this.doors + " doors"); | |
}; | |
//静态工厂方法 子类无法继承 | |
CarMaker.factory = function(type) { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* JavaScript 单体模式 - 最基本结构的单体 */ | |
var Singleton = { | |
attribute1: "public attribute 1", | |
method1: function() { | |
console.log("This is public method1"); | |
// 不保险 若Singleton.method1作为一个事件监听器,那么this就会指向window | |
console.log(this.attribute1); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var fs = require('fs'); | |
//同步读取文件内容 | |
var data = fs.readFileSync('Hello.txt','utf-8'); | |
console.log(data); | |
console.log('End'); | |
/* | |
运行结果: | |
Hello World |
NewerOlder