是否可以使用新的 HTML5 API 创建一个通道,用于在同一域中但在两个不同选项卡/窗口(同一台计算机)中的两个页面实例(或两个不同页面)之间发送消息?
例如,我有一个带有 JavaScript 单页应用程序的页面,当我在一个窗口中单击“注销”或“登录”时,我会在另一个窗口上登录/注销。
没有网络套接字可以做到这一点吗?也许是 WebRTC。我应该如何实现这样的事情?
请参考 - https://jsfiddle.net/ta2u2z9a/
var o = {
x: 6
};
function a() {
this.x = 3;
this.y = function() {
alert(this.x)
}
}
var a1 = new a();
a1.y.call(); //shouldn't it alert 3?
a1.y.call(o) //is alerting 6, correct!
Run Code Online (Sandbox Code Playgroud)
为什么是第一个警报,警告未定义?不应警惕3?
如果我使用此URL来获取"类别"页面
https://en.wikipedia.org/w/api.php?&callback=jQuery111206430303168017417_1453394474227&action=query&prop=revisions&rvprop=content&format=json&titles=Category%3AHacker+(subculture)&_=1453394474245
Run Code Online (Sandbox Code Playgroud)
但我只有标题和其他类别,如何在维基百科上获得与文章列表相同的页面?
我有这样的代码:
string.replace(/(.|\r\n)\x08/g, '');
Run Code Online (Sandbox Code Playgroud)
它将替换退格符和它之前的一个字符,但它不适用于连续有多个退格符的情况,例如'foo\b\b'. 如何删除退格符之前的字符,以便得到 string 'f'。
搜了也没找到,有什么define*诡计吗?例如,您可以在此答案中找到它/sf/answers/1687118961/
我有这样的代码:
class Foo {
var $callbacks = array();
function __construct() {
$this->callbacks[] = function($arg) {
return $this->bar($arg);
};
}
function bar($arg) {
return $arg * $arg;
}
}
Run Code Online (Sandbox Code Playgroud)
我想在闭包中使用 $this ,我尝试添加use ($this)但是这个抛出错误:
Cannot use $this as lexical variable
Run Code Online (Sandbox Code Playgroud) 我尝试使用ng-notifications-bar模块,我有这样的代码:
angular.module('app', [
uiRouter,
Common.name,
Components.name,
angularMaterial,
'ngTable',
'gridster',
'ngNotificationsBar'
])
.factory('$exceptionHandler', ['notifications', function(notifications) {
return function(exception, cause) {
notifications.showError({message: exception});
};
}]);
Run Code Online (Sandbox Code Playgroud)
但有错误:
[$injector:cdep] 找到循环依赖:$rootScope <-通知 <- $exceptionHandler <- $rootScope <- $timeout <- $$rAF <- $mdGesture
我试图修改库来使用$injector,以获得$超时和$ rootScope,但没有帮助还试图用$injector获得notifications的$exceptionHandler工厂,但得到了同样的错误。
是否可以检查对象是否是 JSX 可能是某些执行此操作的函数。我对 React 和 Preact 感兴趣。
var x = <App/>
var y = <div>xxx</div>
Run Code Online (Sandbox Code Playgroud)
我想出了这个:
function isJSX(x) {
return typeof x.props === 'object' && x.props !== null && typeof x.type !== 'undefined';
}
Run Code Online (Sandbox Code Playgroud)
有没有更好的办法?我不确定其他库,如 HyperApp 和 Preact。这个功能可靠吗?输出来自 Babel。是否有规范显示 JSX 转译器的输出应该是什么?
这是我的测试笔
我有两个选择查询:
SELECT MONTH(date) AS month, count(DISTINCT ip)
FROM table_name WHERE field = 1 GROUP BY month
Run Code Online (Sandbox Code Playgroud)
和
SELECT MONTH(date) AS month, count(DISTINCT ip)
FROM table_name WHERE field = 2 GROUP BY month
Run Code Online (Sandbox Code Playgroud)
如何编写一个查询来进行选择
SELECT MONTH(date) AS month,
count(DISTINCT ip) [ for field = 1],
count(DISTINCT ip) [ for field = 2]
Run Code Online (Sandbox Code Playgroud) 我想将我的文本与我的 div 中间对齐,但我似乎无法让它工作。我怎样才能做到这一点?
谢谢您的帮助!
<div style="height:40px;">Personal Information</div>
Run Code Online (Sandbox Code Playgroud)
“个人信息”应位于顶部和底部之间。