object

PHP Don't allow object to instantiate more than once

浪子不回头ぞ 提交于 2020-01-14 05:35:10
问题 I have an abstract class that is inherited by a number of other classes. I'd like to have it so that instead of re-instantiating (__construct()) the same class each time, to have it only initialize once, and utilize the properties of the previously inherited classes. I'm using this in my construct: function __construct() { self::$_instance =& $this; if (!empty(self::$_instance)) { foreach (self::$_instance as $key => $class) { $this->$key = $class; } } } This works - sort of, I'm able to get

How to make objects disappear when poining mouse over them in javascript?

你离开我真会死。 提交于 2020-01-14 05:34:06
问题 So I have this game where a worm eats his food, food randomly spawns on load but I want it to disappear onmouseover and spawn again in another spot but I have no idea what to do :c Didn't find any info on the internet either, tho not quitet sure what to search for. p.s. made this question again because last time people hated it because they thought that I don't have anything done. Thanx <!doctype html> <html> <head> <title>Ussi l6una</title> <script> var kohad=new Array(); var pikkus=1, d=6,

AS3 Passing data between objects/classes

妖精的绣舞 提交于 2020-01-14 05:18:12
问题 So i a building a categorized menu of different foods. I have a class for "categories" (buttons) which essentially will return a string "salads", "drinks", etc. I now have another class "menuItems" for items within categories and this handles sizes such as "small", "med", "large", etc. My problem now is that when i return "salads", i want to invoke an array which contains all the elements of salads, send it to menuItems which will populate the menu. So far i have both the category objects and

What is the difference between Test Objects and Runtime Objects in QTP? Is the given explanation correct?

◇◆丶佛笑我妖孽 提交于 2020-01-14 04:00:09
问题 On a blog about QTP, the following is stated: "All software applications and websites are getting developed using many different components or small units (e.g textbox control in vb, input tag in HTML, webbrowser contorl in .net) which can be called as Objects. Some of the properties can be changed during run-time. These are known as RO (Runtime object) properties. And some of them can not be changed. They are known as TO (Test Object) properties." Is this explanation correct? 回答1: To

how to get the value of the only key-value pair in object [duplicate]

删除回忆录丶 提交于 2020-01-14 03:06:07
问题 This question already has answers here : best way to get the key of a key/value javascript object (16 answers) Closed 5 years ago . I have a javascript object like below, a has only one key-value pair , how could I get the value of a1 without using iteration and also without knowing the key name(i.e a1) ? a: { a1:"hello" } 回答1: Since you said you know there's only one key–value pair in the object: var a = { a1: 'hello' }; Object.keys(a)[0]; var key = Object.keys(a)[0]; a[key]; // yields

原型模式

穿精又带淫゛_ 提交于 2020-01-14 02:26:12
原型模式 定义: 用原型实例指定创建对象的种类,并通过拷贝这些原型创建新的对象。 类型: 创建类模式 类图: 原型模式主要用于对象的复制,它的核心是就是类图中的原型类Prototype。Prototype类需要具备以下两个条件: 实现Cloneable接口。在java语言有一个Cloneable接口,它的作用只有一个,就是在运行时通知虚拟机可以安全地在实现了此接口的类上使用clone方法。在java虚拟机中,只有实现了这个接口的类才可以被拷贝,否则在运行时会抛出CloneNotSupportedException异常。 重写Object类中的clone方法。Java中,所有类的父类都是Object类,Object类中有一个clone方法,作用是返回对象的一个拷贝,但是其作用域protected类型的,一般的类无法调用,因此,Prototype类需要将clone方法的作用域修改为public类型。 原型模式是一种比较简单的模式,也非常容易理解,实现一个接口,重写一个方法即完成了原型模式。在实际应用中,原型模式很少单独出现。经常与其他模式混用,他的原型类Prototype也常用抽象类来替代。 实现代码: class Prototype implements Cloneable { public Prototype clone(){ Prototype prototype = null;

JS: 对象深拷贝

▼魔方 西西 提交于 2020-01-14 02:17:38
浅拷贝:只拷贝数组或者对象的引用,无论在新的或者旧的数组或者对象中作了修改,两者都会发生变化,即两个指向的地址是同一块。 深拷贝:这种拷贝使两者分离,修改一个对象的属性,另外一个也不会有影响,即深拷贝会把所有东西重新复制一份放在另一个地方,两者指向的不是同一块地址。 1. JSON.stringify() &JSON.parse() 将JSON.stringify对象转换成字符串,然后通过JSON.parse将字符串转换成对象 var obj = {a:1, b:2, c:3}; var obj2 = JSON.parse(JSON.stringify(obj)); obj2.a = 2; console.log(obj.a); console.log(obj2.a); 上面的结果输出分别是:1和2 说明obj 和 obj2之间没有关系了,实现深拷贝 缺点:只能用于对象属性的深拷贝不能用于对象方法的拷贝 var arr = [function(){ console.log(a) }, { b: function(){ console.log(b) } }] var new_arr = JSON.parse(JSON.stringify(arr)); console.log(new_arr);  输出结果: 2. Object.assign(),可以实现对象属性和方法的深拷贝

SQL SERVER拓展存储过程

≡放荡痞女 提交于 2020-01-14 01:44:23
一直都是C#调用数据库的对象,这里介绍的拓展存储过程可以在DB中调用C#的dll并且返回到DB一些信息(表或者字符串) C#代码如下,主要用以返回一个路径下面的文件,用以测试 下面只是为了创建一个类库,从而产生一个dll,所以操作如下: using Microsoft.SqlServer.Server; using System; using System.Collections; using System.Collections.Generic; using System.Data.SqlTypes; using System.IO; using System.Linq; using System.Text; using System.Text.RegularExpressions; using System.Threading.Tasks; public partial class UserDefinedFunctions { [SqlFunction(FillRowMethodName = "FillRow")] public static IEnumerable DirectoryList(string sRootDir, string sWildCard, bool bIncludeSubDirs) { ArrayList aFileArray = new

C#弱引用

左心房为你撑大大i 提交于 2020-01-13 20:38:57
.NET框架提供了另一有趣的特色,被用于实现多样的高速缓存。在.NET中弱引用通过System.WeakReference类实现。弱引用为引用的对象提供一项机制,使被引用的对象能够被垃 圾收集器作用。ASP.NET高速缓存就使用了弱引用。如果内存使用率太高,高速缓存将被清除。 强制垃圾收集 .NET框架为开发者提供System.GC类来控制垃圾收集器的一些方面。垃圾收集可以通过调用GC.Collect方法强制执行。通常建议不要手动的调用垃圾收集器,而将其设置为自动方式。在某些情况下,开发者会发现强制垃圾收集将推进性能。但是,使用这个方法需要非常小心,因为在垃圾收集器运行时将延缓当前执行的线程。GC.Collect方法不应位于可能被经常调用的地方。这样做将使应用程序的性能降级。 构造函数: WeakReference 初始化 WeakReference 类的新实例。 此构造函数重载不能在基于 Silverlight 的应用程序中实现。 WeakReference(Object) 引用指定的对象初始化 WeakReference 类的新实例。 WeakReference(Object, Boolean) 初始化 WeakReference 类的新实例,引用指定的对象并使用指定的复活跟踪。 属性: IsAlive 获取当前 WeakReference 对象引用的对象是否已被垃圾回收的指示

Accessing class constants from instance stored in another class

匆匆过客 提交于 2020-01-13 20:34:06
问题 I have a class defined which has several constants defined through `const FIRST = 'something'; I have instantiated the class as $class = new MyClass() then I have another class that takes a MyClass instance as one of it's constructors parameters and stores it as $this->model = $myClassInstance; This works fine. But I am wondering how I can access the constants from that instance? I tried case $this->model::STATE_PROCESSING but my IDE tells me Incorrect access to static class member. and PHP