java.lang.Class.<init>()方法的使用及代码示例

x33g5p2x  于2022-01-16 转载在 其他  
字(4.4k)|赞(0)|评价(0)|浏览(306)

本文整理了Java中java.lang.Class.<init>()方法的一些代码示例,展示了Class.<init>()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Class.<init>()方法的具体详情如下:
包路径:java.lang.Class
类名称:Class
方法名:<init>

Class.<init>介绍

暂无

代码示例

代码示例来源:origin: stackoverflow.com

  1. };
  2. var obj2 = new Class();

代码示例来源:origin: stackoverflow.com

  1. function Class() {};
  2. Class.prototype.foo = function() {alert("foo");};
  3. function Subclass() {};
  4. Subclass.prototype = new Class();
  5. Subclass.prototype.bar = function() {alert("bar");};
  6. var a = new Class(), b = new Subclass();
  7. a.foo(); // alerts"foo"
  8. a.bar(); // throws an error
  9. b.foo(); // alerts "foo"
  10. b.bar(); // alerts "bar"
  11. a instanceof Class; // true
  12. a instanceof Subclass; // false
  13. b instanceof Class; // true
  14. b instanceof Subclass; // true

代码示例来源:origin: stackoverflow.com

  1. function Class() {
  2. this.constructor.prototype.method = function () {};
  3. }
  4. console.log(typeof Class.prototype.method); // "undefined"
  5. var a = new Class();
  6. console.log(typeof Class.prototype.method); // "function"

代码示例来源:origin: stackoverflow.com

  1. var method = a.method;
  2. console.log(a.method === method); // true
  3. var b = new Class();
  4. console.log(a.method === method); // false

代码示例来源:origin: stackoverflow.com

  1. Class obj; //obj is just a reference(not an object)
  2. obj = new Class();// obj refers to the object

代码示例来源:origin: stackoverflow.com

  1. var Notifier = new Class({
  2. showMessage: function(message) {
  3. },
  4. setElementClass: function(klass) {
  5. }.protect()
  6. })​;
  7. var notifier = new Notifier();
  8. notifier.showMessage();
  9. notifier.setElementClass();
  10. > Uncaught Error: The method "setElementClass" cannot be called.

代码示例来源:origin: stackoverflow.com

  1. Notifier.Email = new Class({
  2. Extends: Notifier,
  3. sendEmail: function(recipient, message) {
  4. // can call the protected method from inside the extended class
  5. this.setElementClass('someClass');
  6. }
  7. });
  8. var emailNotifier = new Notifier.Email();
  9. emailNotifier.sendEmail("a", "b");
  10. emailNotofier.setElementClass("someClass");
  11. > Uncaught Error: The method "setElementClass" cannot be called.

代码示例来源:origin: stackoverflow.com

  1. require("mootools");
  2. // globals exported and types shimmed
  3. var foo = new Class({}); // etc

代码示例来源:origin: stackoverflow.com

  1. for (var i = 0; i < 100000; i++) {
  2. var x = new Class();
  3. console.log(x.p1);
  4. // ignore p2-p99. we don't need them right now.
  5. }

代码示例来源:origin: stackoverflow.com

  1. function Class(){
  2. this.obj = {};
  3. }
  4. var a = new Class();
  5. a.obj.x = 5;
  6. var b = new Class();
  7. console.log(b.obj.x); // undefined

代码示例来源:origin: stackoverflow.com

  1. var myclass = new Class({
  2. Implements: [Options],
  3. options: { // default options:
  4. foo: "foobar"
  5. },
  6. initialize: function(options) {
  7. this.setOptions(options);
  8. alert(this.options.foo);
  9. }
  10. });
  11. new myclass({foo: "bar"}); // alerts bar
  12. new myclass(); // alerts foobar

代码示例来源:origin: stackoverflow.com

  1. var instances = [
  2. new Class(), new Class(), new Class()
  3. ];
  4. for (var i = 0; i < 1000000; i++) {
  5. console.log(instances[i % instances.length].p1);
  6. console.log(instances[i % instances.length].p2);
  7. console.log(instances[i % instances.length].p3);
  8. }

代码示例来源:origin: stackoverflow.com

  1. // Create an instance
  2. var c = new Class();
  3. // At some point, initiate loading the value
  4. c.setAttr1();
  5. // At some point, look to use the value
  6. c.accessAttr1().then(function(inst) {
  7. console.log(inst.attr1);
  8. });
  9. // Somewhere else, look to use the value
  10. c.accessAttr1().then(function(inst) {
  11. doSomethingElseWith(inst.attr1);
  12. });

代码示例来源:origin: stackoverflow.com

  1. var Class = function(){};
  2. Class.prototype = {};
  3. Class.staticMethod = function(){ alert('static method'); };
  4. Class.prototype.instanceMethod = function(){ alert('instance method'); };
  5. var instance = new Class();
  6. Class.staticMethod(); // works
  7. Class.instanceMethod(); // doesn't work
  8. instance.staticMethod(); // doesn't work
  9. instance.instanceMethod(); // works

代码示例来源:origin: stackoverflow.com

  1. function Class(){}
  2. Class.prototype = { obj : {}};
  3. var a = new Class();
  4. a.obj.x = 5;
  5. var b = new Class();
  6. console.log(b.obj.x); // 5

代码示例来源:origin: stackoverflow.com

  1. function Class(){}
  2. Class.prototype = { val : 5};
  3. var a = new Class();
  4. console.log(a.val); // 5
  5. a.val = 6;
  6. console.log(a.val); // 6
  7. var b = new Class();
  8. console.log(b.val); // 5

代码示例来源:origin: stackoverflow.com

  1. Class name;
  2. try {
  3. name = new Class();
  4. } catch (Exception e) {
  5. do something
  6. }

代码示例来源:origin: stackoverflow.com

  1. var obj = new Class();
  2. obj.method(); // 1;
  3. var unbound = obj.method;
  4. unbound(); // undefined;
  5. // Call and Apply setting the context to obj.
  6. unbound.apply(obj); // 1
  7. unbound.call(obj); // 1;
  8. // ECMAScript 5's bind
  9. var bound = unbound.bind(obj);
  10. bound(); // 1;

代码示例来源:origin: stackoverflow.com

  1. Class name;
  2. try
  3. {
  4. name = new Class();
  5. }
  6. catch (Exception exp)
  7. {
  8. exp.printStackTrace();
  9. }

代码示例来源:origin: stackoverflow.com

  1. var My = {
  2. SomeClass: new Class(..),
  3. OtherClass: new Class(..)
  4. };
  5. var object = new My['SomeClass']();

相关文章

Class类方法