golang中实现自定义数据类型struct

可以参考:golang中的函数

func.go

package main

import (
"fmt"
)

type stu struct {
Name string //首字母大写,允许其它包直接使用,可以直接使用 stu.Name = 'test' 也可以使用 setName和getName
age int //不允许外面的包使用,可以使用 setAge和getAge方法
}

func main() {

perl := new(stu)
perl.Name = "zhang"

// age
setAge(perl, 30)
age := getAge(perl)

fmt.Printf("%v\n", age)

//name
var name string
perl.setName("sun")
name = perl.getName()

fmt.Printf("%i\n", name)

//print struct
fmt.Printf("%v\n", perl)
}

func setAge(s *stu, age int) {

s.age = age
}

func getAge(s *stu) int {
return s.age
}

//========= 另一种写法

func (s *stu) setName(name string) {
s.Name = name
}

func (s *stu) getName() string {
return s.Name
}

对于结构体struct的初始化的几种方法,见:http://blog.haohtml.com/archives/14239

开发jquery插件

jquery插件开发文档:http://www.tripfox.com.cn/node/64

以下为一简单的实例:

chajia.js:

(function($) {
//录入框点击事件
$.fn.alertWhileClick = function() {

$(this).click(function(){
window.console.log(‘execute click event’);
alert($(this).val());
});

window.console.log(‘ok2’);
}

//获取页面最大div的最大高度
$.fn.maxHeight = function(){
var max = 0;

this.each(function(){
window.console.log(‘a’);
max = Math.max(max, $(this).height());
});
return max;
}
})(jQuery);

//插件用法
$(function(){

$(‘#login_username’).alertWhileClick();

var tallest = $(‘div’).maxHeight();
alert(tallest);
})