js和java写法中this标签的误区
来源:互联网 发布:网络暴力现象分析 编辑:程序博客网 时间:2024/05/16 05:11
2016年8月28日 每周一篇博客
1.this作用域的问题
var treeObj = {
initParam:function(){
var setting = {
async: {
enable: true,
url: baseURL+ '/URL1',
autoParam: ["id"]
},
data:{
simpleData:{
enable:true,idKey:"id",pIdKey:"pId",rootPId:'0'}
},
callback:{onClick:function(event, treeId, treeNode){
var id = treeNode.id == '0' ? '' :treeNode.id;
$('#categoryContent').attr("src",ctx+"/URL2?guid="+id);
treeObj.createTree();
//错误写法this.createTree(); 这里的this指的是setting
}
};
return setting;
},
createTree:function(){
var setting = this.initParam();
$.getJSON(baseURL+ "/URL3",function(data){
$.fn.zTree.init($("#ztree"), setting, data).expandAll(false);
});
}
}
2.额外补充在java中this的误区。
在一个类继承它的父类比如:
public class A{
private String id ;
public void setId(String id) {
this.id= id == null ? null : id.trim();
}
public String getId() {
return id;
}
}
A的子类
public class B extends A{
puclic B(String id){//有参的构造方法
// this.id = id ; 错误写法
//super.id = id ; 错误写法
setId(id) ; //正确写法
}
}
- js和java写法中this标签的误区
- 关于function中使用this的误区
- js中with和this的用法
- JS 中 和 JQuery 的 this 关键字
- Java中SimpleDateFormat的误区
- js 标签事件写法
- jquery中this与$(this)的用法区别.和于js中的this区别
- jquery中this与$(this)的用法区别.和于js中的this区别
- jquery中this与$(this)的用法区别.和于js中的this区别
- jquery中this与$(this)的用法区别.和于js中的this区别
- jquery中this与$(this)的用法区别.和于js中的this区别
- js中this和that
- js中普通类和单实例类的写法
- 项目中多余的js写法之join和||连用
- React.js中ES6 和 ES5写法的一些差别
- js中时间的写法
- js 中定时器的写法
- JS中模块的写法
- easyui tree拖动事件
- 写给matlab新手的几句话[转]
- lua 5.2 的 _ENV
- xtrabackup热备一致性原理
- HBase Shell 常用命令
- js和java写法中this标签的误区
- (mysql for Linux) CentOs中mysql的安装与配置
- 【算法系列-5】动态规划-背包问题
- 解决TCP延迟应答(Delay ACK)问题的3个小Trick-(续:正规的做法)
- BZ2599(树分治填坑)
- ToolBar、沉浸式状态栏的应用(简单粗暴)
- dll函数偏移地址获取方式方法
- APP开发实战136-APP常用功能设计
- WordPress搭建