现在的位置: 首页 > 综合 > 正文

Extjs:定义对象

2018年03月23日 ⁄ 综合 ⁄ 共 1035字 ⁄ 字号 评论关闭

导读:

  Javascrīpt没有namespaces概念或class关键字, 但是对象定义却有很多种方式。在js中使用对象往往只是用来减少对全局函数namespace的污染。

  最简单的方式是使用直接量的语法,它适合于单个的实例,比如整体布局,或窗体部件。不使用"new"来创建。

  

  aaa = {

  ccc: "test",

  bbb : function() { alert(this.cc); }

  }

  aaa.bbb();

  

  好处是调式的时候可以很方便的访问内部变量。

  Class definitions with private variables

  

  aaa = (function () {

  var myprivate;

  return {

  setIt: function(val) { myprivate = val; }

  getIt: function() { return myprivate; }

  }

  })();

  

  我目前的用法function AAA() {

  var myprivate;

  this.setIt = function(val) { myprivate = val; }

  this.getIt = function() {return myprivate; }

  }

  aaa = new AAA();

  

  在extjs中,这种方法的使用很普遍。它限制了对私有变量的访问,也造成调试的不便。

  Extending objects with Ext.extend

  

  function MyCombo (config) {

  // set up your datasource here..

  MyCombo.superclass.constructor.call(this,config);

  }

  Ext.extend(MyCombo, Ext.form.ComboBox, {

  displayField:'title',

  typeAhead: true,

  loadingText: 'Searching',

  forceSelection: true,

  allowBlank: false,

  width: 160,

  minChars: 1,

  pageSize:10,

  hideTrigger:true,

  displayField: 'FullName',

  valueField: 'id'

  }

  

本文转自

http://www.blogjava.net/coder/articles/125148.html

【上篇】
【下篇】

抱歉!评论已关闭.