当我的页面加载时,我尝试向send服务器发送一条消息以启动连接,但它无法正常工作.此脚本块位于我的文件顶部附近:
var connection = new WrapperWS();
connection.ident();
// var autoIdent = window.addEventListener('load', connection.ident(), false);
Run Code Online (Sandbox Code Playgroud)
大多数时候,我看到标题中的错误:
未捕获的InvalidStateError:无法在'WebSocket'上执行'send':仍处于CONNECTING状态
所以我尝试catch了异常,正如你在下面看到的那样,但现在它似乎InvalidStateError没有定义,并产生了一个ReferenceError.
这是我的websocket连接的包装器对象:
// Define WrapperWS
function WrapperWS() {
if ("WebSocket" in window) {
var ws = new WebSocket("ws://server:8000/");
var self = this;
ws.onopen = function () {
console.log("Opening a connection...");
window.identified = false;
};
ws.onclose = function (evt) {
console.log("I'm sorry. Bye!");
};
ws.onmessage = function (evt) {
// handle messages here
};
ws.onerror = function …Run Code Online (Sandbox Code Playgroud) 在JavaScript Prototype继承中,添加prototype.constructor属性的目标是什么.让我举个例子来解释一下.
var Super = function() {
this.superProperty = 'Super Property'
}
var Sub = function() {
this.subProperty = 'Sub Property'
}
Sub.prototype = new Super();
Sub.prototype.constructor = Sub; // advantages of the statement
var inst = new Sub();
在添加Sub.prototype.constructor = Sub时,以下行在所有情况下都返回true.
console.log(inst instanceof Sub) // true console.log(inst instanceof Super) // true
我猜,它在获取新实例时可能会有用但是何时和/或如何?
提前致谢.
我有一个图像缩放功能,可以按比例调整图像大小.在每个图像上加载一个调用此函数的图像,如果其宽度或高度大于我的最大宽度和最大高度,则调整大小.我可以在FF Chrome Opera Safari中获得img.width和img.height但是IE失败了.我怎么处理这个?
让我用一段代码解释一下.
<img src="images/img01.png" onload="window.onImageLoad(this, 120, 120)" />
function onImageLoad(img, maxWidth, maxHeight) {
var width = img.width; // Problem is in here
var height = img.height // Problem is in here
}
在我的高亮度行中,img.width不适用于IE系列.
有什么建议吗?
谢谢.
我已经尝试过并且惊讶于如何使用ExtJS.让我用代码块解释一下.
在jQuery中
console.clear();
var a = {
b: 5,
c: 4,
o: {
l: 2,
p: 2
}
}
var b = {
k: 4,
l: 3,
c: 5,
o: {
m: 2,
l: 1
}
}
var ex = $.extend(true, a, b);
console.dir(ex)
这是输出
ex = {
a: {
q: 2
},
b: 5,
c: 5,
o: {
l: 1,
p: 2,
m: 2
}
}
Ext apply,applyIf,copyTo不能像这样工作.如何在ExtJS中生成输出?
提前致谢.
我有jQuery Drag&Drop的问题.我有一个draggable元素和很多dropTarget所以我只想知道我什么时候拖动,我的拖动元素是哪个元素?
顺便说一句,Firefox提供了指向DOM元素的event.originalTarget,但在Google Chrome中它等于"undefined".
有什么建议吗?
谢谢.
jquery drag-and-drop jquery-ui draggable jquery-ui-draggable
我对这两种向函数添加方法的方式感到困惑.让我举个例子来解释一下.
var foo = function(){
this.bar = function(){alert('I am a method')}
}
foo.prototype.baz = function(){alert('I am another method')}
var car = new foo();
现在,在这一点上我们可以使用汽车的baz和bar方法.好吧,但它们之间有什么区别.为函数原型或它的构造函数添加方法的细微差别是什么.
谢谢..
我正在处理财产网格.我想阻止属性网格的列名称的自动排序.这是我的代码.大胆突出显示的代码是我的属性网格源,它的顺序就像我想看到的那样.但Ext是按字母顺序自动排序列顺序.我怎么能防止这种情况.
谢谢你的任何建议.
Ext.ns('Application.propertygrid');
Application.propertygrid.FileDetail = Ext.extend(Ext.grid.PropertyGrid, {
title: 'File Detail',
height: 200,
border: false,
stripeRows: true,
flex: 1,
initComponent: function () {
Application.propertygrid.FileDetail.superclass.initComponent.apply(this, arguments);
},
source: {
Name: 'Please select a file',
Type: 'Please select a file',
Size: 'Please select a file',
Path: 'Please select a file',
FullPath: 'Please select a file',
Width: 'Please select a file',
Height: 'Please select a file'
},
listeners: {
beforeedit: function(){
return false; // prevent editing
},
headerclick: function(){
return false; // prevent column … javascript ×4
constructor ×2
extjs ×2
prototype ×2
deep-copy ×1
draggable ×1
extend ×1
function ×1
image ×1
inheritance ×1
jquery ×1
jquery-ui ×1
object ×1
oop ×1
propertygrid ×1
websocket ×1